• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

regarding top level classes

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For classes there can only be the public or default access

The following code will also not compile
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Top level classes mean that classes that are not inner classes, not the classes which have a main method.
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic