• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Help me in Packages in Java  RSS feed

 
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
 
author and iconoclast
Posts: 24203
43
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
 
CAUTION! Do not touch the blades on your neck propeller while they are active. Tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!