It's not a secret anymore!*
The moose likes Java in General and the fly likes Help me in Packages in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Help me in Packages in Java" Watch "Help me in Packages in Java" New topic
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: 24183
    
  34

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help me in Packages in Java
 
Similar Threads
Doubts on Protected Members
conflict: inheritance, package and import access
Classpath Problem
doubt
scope question