• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regarding top level classes

 
vatsalya rao
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
till now i understood that a top level class cant be private means any class that contains "MAIN" method cannot be private.

see the following code:


private class Base{}
public class Vis
{
transient int iVal;
public static void main(String elephant[])
{
}
}
when this code is compiled syaing that the class "Base" can not be private.
a top level class cant be private means any class that appears at first cant be private?
 
Remko Strating
Ranch Hand
Posts: 893
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For classes there can only be the public or default access

The following code will also not compile
 
Ravi Pinnaboyina
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Top level classes mean that classes that are not inner classes, not the classes which have a main method.
 
Prasad Shindikar
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
except for public, final and default(ie if modifier not specified), none of the access modifiers can be used with a class.

hence your code will not compile
 
Jetendra Ivaturi
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There can be any no. of toplevel classes. But we can give only public or defalult access specifiers.

It's not that the main method() should only be in top-level class. Main method can also be in inner class, but they can be declared private.
 
murthy ramana
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi folks,

i think inner classes cant have static declarations - so we cant write main() in an inner class.

thanks and regards,
murthy kvr
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic