| Author |
Help me in Packages in Java
|
sri narayanan
Greenhorn
Joined: Jul 12, 2006
Posts: 4
|
|
this is my program. Code 1:Inside pack folder:saved as VGS.java package Pack; public class VGS { public void doFunc() { System.out.println("i am in package Frontier but in class VGS"); } public class VGS2 { public void doFunc2() { System.out.println("i am in package Frontier but in class VGS2"); } } } code 2: Outside Pack folder:saved as Crog.java import Pack.*; class Crog { public static void main(String arg[]) { VGS v = new VGS(); v.doFunc(); VGS2 b = new VGS1(); b.doFunc2(); } } when i compile the code 2 ..i am getting an error saying that class VGS2 is oublic,so it should saved as VGS2.java my question is....cant we use two or more classes from a package without having a main module(i.e.,public static void main())in that package. pls clarify me... Sriram
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24061
|
|
Hi, Welcome to JavaRanch! The problem is that you can't put more than one public class in a *.java file. Put the two VSG* classes each in their own file, with a name that matches the class, and put both files in the Pack directory.
|
[Jess in Action][AskingGoodQuestions]
|
 |
sri narayanan
Greenhorn
Joined: Jul 12, 2006
Posts: 4
|
|
hey, thanks a lot. sriram
|
 |
 |
|
|
subject: Help me in Packages in Java
|
|
|