Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

my code does not compile plz help me

 
ganesh pol
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i hava Defined 2 classes
Test class in package test
A class in package A
code is given below

////////////////////////////////////////////////////
package test;
import A ;
public class Test
{
public static void main(String[] args)
{
A a = new A();
a.print("Hi");
System.out.println("Hello World!");
}
}

/////////////////////////////////////////
package A;
public class A

{
public static void main(String[] args)
{ String s1= "Ganesh";
Integer i1= new Integer(1);
System.out.println("Hello World!");
System.out.println(s1);
//System.out.println(new SimpleDateFormat("yyy mm dd"));
}

public void print(String s1) {
System.out.println(s1);
}
}

i have created object of class A in class Test but does not compile

class A Compiles but Test class in package test does not compile
 
ganesh pol
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
note Both A and test are in a Same Folder
 
Steve Morrow
Ranch Hand
Posts: 657
Clojure Spring VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Package names should be lowercase; don't name your class the same name as a package.
 
Steve McCann
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your files should be in different folders reflecting the package structure. Also, your import statement needs to be updated with either the class name or the * wildcard. Have a look at the Java Tutorial for more info on using packages etc.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe the above suggestions should help you figure out how to fix the problem. If not, please post the EXACT compiler error message along with some indication of which line each message refers to. This will help us tell you EXACTLY what is wrong without trying to guess what the problem is.

Layne
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic