Solved

'.' expected

Posted on 2006-07-11
4
185 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
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
factorial example 4 48
Need help aligning JRadioButton that put in a box using GridBagLayout 2 18
web project error add remove 1 29
jsp error 6 26
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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
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.

860 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