MODIFIERS

Def: - Modifiers are Java keywords that give the compiler information about its nature of code, data, or classes.

The Access Modifiers

At most 1 access modifier may be used at a time.

Legal overridden method access


Methods may not be overridden to be more private. For example, a protected method can't be overridden by a default one. But you can override a default method to make it protected or public.

public

It's the most generous access modifier. A public class, variable, or method may be used in any Java Program without restriction. For example, an Applet is public so that it may be instantiated by browsers. A main() method is also declared public so that it may be invoked from any Java runtime environment.

private

It's the least generous access modifier. A top level-class may not be declared private. A private variable or method may be used by an instance of the class that declares that variable or method. You can't invoke methods or variables declared private from outside. Methods or variables that the user of a class won't use, should be declared private.

Default

Default is not a Java keyword, it is simply the name that is given to the access level that results from non specifying an access modifier.

0 comments:

Post a Comment