Solved

'.' expected

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

733 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