aspose file tools*
The moose likes Beginning Java and the fly likes private class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "private class" Watch "private class" New topic
Author

private class

varungoyal goyal
Ranch Hand

Joined: May 31, 2006
Posts: 37
Is there any rule that class having main method cannot be private..thanks
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

I don't think so, as long as at least one class has a main method public.


[My Blog]
All roads lead to JavaRanch
Sri Ram
Greenhorn

Joined: Feb 13, 2006
Posts: 20
The access modifiers that can be applied to a class are only public and default. protected and private access modifiers cannot be applied to any class.


Sriram<br />SCJP<br />SCWCD
Tanka Banerjee
Ranch Hand

Joined: Aug 16, 2006
Posts: 64
main can't be private , and the class with the main method should be public.
class Hi.java :
public class Hi {
private static void main(String[] args)
{
System.out.println("Hi Bo ");
}
}
Runtime error main method not public.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Runtime error main method not public.

Did you read my post ?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39393
    
  28
Quoted by Sri Ram
protected and private access modifiers cannot be applied to any class.
You can certainly have a private class. It has to be set up as an inner class, but private inner classes work nicely.
varungoyal goyal
Ranch Hand

Joined: May 31, 2006
Posts: 37
sir what is the use of making "public static void main " as a " private static void main
ramesh kumar
Greenhorn

Joined: Aug 15, 2006
Posts: 25
we should not declare any class so,it would not be meaning full
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3646
    
  15
Originally posted by varungoyal goyal:
sir what is the use of making "public static void main " as a " private static void main


If you make any method private and static, it can only be called from within its class. One use might be a method that you don't want to be generally available, but you do want to call from another public static method.
There is nothing to stop you naming this method main. You just won't be able to use it as an entry point to your program.


Joanne
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: private class