• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

private class

 
varungoyal goyal
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any rule that class having main method cannot be private..thanks
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think so, as long as at least one class has a main method public.
 
Sri Ram
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tanka Banerjee
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Runtime error main method not public.

Did you read my post ?
 
Campbell Ritchie
Sheriff
Posts: 48386
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sir what is the use of making "public static void main " as a " private static void main
 
ramesh kumar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we should not declare any class so,it would not be meaning full
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic