Click here to Skip to main content
16,018,949 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In Java I have seen code where people use public before class keyword,what does that mean?
Is it same like if class keyword is only used?
one such piece of code mentioned below.

Java
public class CableModem extends Modem 
{
 String method = "cable connection";

public void connect() 
{
 System.out.println("Connecting to the Internet ...");
 System.out.println("Using a " + method);
}
 

}
Posted
Comments
Sergey Alexandrovich Kryukov 25-Jul-13 17:29pm    
Do you think that reading of reference manual by yourself is not enough? Why do you need that someone else read it for you?
—SA

 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-Jul-13 17:30pm    
5ed.
—SA
bbirajdar 26-Jul-13 0:46am    
:)
Prasad Khandekar 26-Jul-13 6:24am    
My 5+ as well.
bbirajdar 26-Jul-13 6:29am    
:)
The public keyword is an access specifier, which allows to control the visibility of class members. When a class member is declared as 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-short:
Public - means the class (program) is available for use by any other class.
 
Share this answer
 
v2
Comments
ridoy 26-Jul-13 2:08am    
Answer accepted,and then downvoted..really funny!:)
bbirajdar 26-Jul-13 2:51am    
My answer was also downvoted ... But I give you 5 :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900