Friday 1 September 2017

Java Acces Modifiers

Cited from the Book Java How to Program

The method declaration begins with keyword public to indicate that the method is “available to the public”—it can be called from methods of other classes.
Java class declarations normally contain one or more methods. For a Java application, one of the methods must be called main.

If an application has multiple classes that contain main, the one that’s invoked is the one in the class named in the java command.

Most instance-variable declarations are preceded with the keyword private (as in line 7). Like public, keyword private is an access modifier. Variables or methods declared with access modifier private are accessible only to methods of the class in which they’re declared.

Declaring instance variables with access modifier private is known as data hiding or information hiding.

No comments:

Post a Comment