Solved

'.' expected

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java Options in Zimbra Server 2 50
Arrays.asList  VS  ArrayList 4 56
How to execute a Python program and gather return output in Java 2 26
jsp login check 12 29
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

786 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