What is public class and public static void main?
What does Show I'm in the process of learning. In all the examples in the book I'm working from
asked Mar 5, 2010 at 21:27
0 It's three completely different things:
The combination of all three of these is most commonly seen on the
answered Mar 5, 2010 at 21:29
Mark ByersMark Byers 785k188 gold badges1552 silver badges1440 bronze badges 3 The three words have orthogonal meanings.
answered Mar 5, 2010 at 21:30
Thomas PorninThomas Pornin 71.8k14 gold badges146 silver badges188 bronze badges 0
The public keyword is an access specifier, which allows the programmer to control the visibility of class members. When a class member is preceded by public, then that member may be accessed by code outside the class in which it is declared. (The opposite of public is private, which prevents a member from being used by code defined outside of its class.) In this case, The keyword static allows The keyword void simply tells the compiler that
khr055 28.4k16 gold badges35 silver badges47 bronze badges
answered Sep 4, 2012 at 18:02
utsavutsav 3813 silver badges3 bronze badges 0 It means that:
You'd think that the lack of a return means it isn't doing much, but it might be saving things in the database, for example.
answered Mar 5, 2010 at 21:30
Paul TomblinPaul Tomblin 176k58 gold badges314 silver badges401 bronze badges It means three things. First
Since you are just learning, don't worry about the first two too much until you learn about classes, and the third won't matter much until you start writing functions (other than main that is). Best piece of advice I got when learning to program, and which I pass along to you, is don't worry about the little details you don't understand right away.
Get a broad overview of the fundamentals, then go back and worry about the details. The reason is that you have to use some things (like
StudioTime 21.6k37 gold badges114 silver badges205 bronze badges answered Mar 5, 2010 at 21:32
AaronAaron 1,0626 silver badges16 bronze badges Considering the typical top-level class. Only public and no modifier access modifiers may be used at the top level so you'll either see public or you won't see any access modifier at all. `static`` is used because you may not have a need to create an actual object at the top level (but sometimes you will want to so you may not always see/use static. There are other reasons why you wouldn't include static too but this is the typical one at the top level.)
Disclaimer: I'm a newbie myself so if this answer is wrong in any way please don't hang me. By day I'm a tech recruiter not a developer; coding is my hobby. Also, I'm always open to constructive criticism and love to learn so please feel free to point out any errors.
answered Aug 25, 2012 at 16:06
1
answered Mar 6, 2011 at 19:11
gnat 6,210104 gold badges53 silver badges73 bronze badges answered Jan 16, 2012 at 13:37
2
answered Jan 8, 2014 at 6:08
mahimahi 415 bronze badges What is public in public static void main?It is an Access modifier, which specifies from where and who can access the method. Making the main() method public makes it globally available. It is made public so that JVM can invoke it from outside the class as it is not present in the current class.
What is public class and public void?A class is a collection of methods and data. Public means that the class can be accessed by any other class in any package. main is a method of the class. Static means it is defined as a member of the class rather than a member of an instance of the class. Void means it returns nothing.
What is the difference between public static void main and static void Main?public − This is the access specifier that states that the method can be accesses publically. static − Here, the object is not required to access static members. void − This states that the method doesn't return any value.
What is the difference between public void and public static void?Public void : Used when you don't have to create an object and have no return. Public static void: Used when you need to create an object in the class itself .
|