Solved

'.' expected

Posted on 2006-07-11
4
187 Views
Last Modified: 2010-03-31
Hello!

I have written 2 java classes


-----------------------test.java---------------------------
public class test
{
      int a;
      
      test()
      {
            a=1;
      }
      
      void seta(int pa)
      {
            a = pa;
      }
      
      void printa()
      {
            System.out.println("The value of a is " + a);
      }
}
----------------------------------------------------------------------


------------------------test1.java-----------------------------------


import test;

public class test1
{
      public static void main(String args [])
      {
            test ltest= test();
            ltest.seta(10);
            ltest.printa();
      }
}

----------------------------------------------------------------------


The jdk I am using is v1.4.2_11-b06
javac works fine for compiling test.java but I have problem when compiling test1.java
Here is the output capture:

D:\temp>javac -classpath d:\temp test1.java
test1.java:1: '.' expected
import test;
           ^
1 error


Experts, please suggest what to do!

Many Thanks!!!

Regards,
Bessie
0
Comment
Question by:bessie1215
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 24

Expert Comment

by:slyong
ID: 17087721
Hi Bessie,

You cannot import test.  If you want to use import, you have to create test as a package.  There is a tutorial here that explains it pretty clearly: http://jarticles.com/package/package_eng.html
0
 

Author Comment

by:bessie1215
ID: 17087738
slyong, Thanks for your prompt reponse.

Is there any other approaches if i really want to use test in test1 without modifying test as a package?
0
 
LVL 24

Accepted Solution

by:
slyong earned 500 total points
ID: 17087741
Had another looked at your code, you want to instanciate test in test1.  Just remove the line
import test;

and compile.  There is an error in your test1.java program too:

          test ltest= test();
should be
          test ltest= new test();
0
 

Author Comment

by:bessie1215
ID: 17087757
Thanks slyong
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question