Solved

'.' expected

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now