Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not able to create package

 
Akhil Jain
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please note: i am using Gel as Java Editor

//<----first file:----->

package mypackage;

public class class1{
private int data;
class1(){
data=100;
}
public void func(){
System.out.println(data);
return;
}
}

//<-----Second file---->

import mypackage.*;

public class class2{
public static void main(String[] args){
class1 obj = new class1();
obj.func();
System.out.println("Done Successfully");
}
}

i am compling the first program and it should create the package inside the main working directory but ir is not creating.

and while compling the second file its unable to get the package and hence giving package doesn't exist error.

If some can help me out then please do reply soon.

Note that i am using Gel editor for java.
 
Arnaud Burlet
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your class1.java should be in a directory named "mypackage",
your class2.java should be in the same directory as "mypackge" dir.



And to have your example work, you should declare class1 constructor as public.

Arnaud
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic