Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help me in Packages in Java

 
sri narayanan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
sri narayanan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey,
thanks a lot.

sriram
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic