JAVA ACCESS MODIFIERS

3 Nov

Access modifiers: public, protected, private, default
Non-access modifiers (strictfp, final, abstract, transient, synchronized, native).

A class can be declared with only public or default access; the other two access control levels don’t make sense for a class

Methods can be declared with any of the four access modifiers.

Even a single method is abstract, the whole class must be declared abstract.

An abstract class must be subclassed, whereas a final class must not be subclassed.

Abstract class can have both abstract and non-abstract methods, whereas interface will have only abstract methods.
All interface methods are implicitly public and abstract.
Interface methods must not be static
All interface variables must be public, static, and final— in other words, interfaces can declare only constants, not instance variables.

A class with a protected member is marking that member as having package-level access for all classes, but with a special exception for subclasses outside the package.

For a subclass outside the package, the protected member can be accessed only through inheritance.

Once the subclass-outside-the-package inherits the protected member, that member (as inherited by the subclass) becomes private to any code outside the subclass, with the exception of subclasses of the subclass.

Public member is like a public community hall or public toilet – Anybody from any generation can use them
Protected member is like GENE (DNA)
• In the same house(package), all will have the same GENE
• Children and their generation from the main house, who are now in different houses will also have the GENE
Private member is like a person’s underwear, only he can use it.
Default member is like a Washing Machine in the home, only persons and generations of the home (package) can use it.

PUBLIC : ஊருக்கே சொந்தம்
PROTECTED : ரத்த சொந்தங்களுக்கு மட்டும்
DEFAULT : ஒரு வீட்டு ஆளுங்களுக்கு மட்டும்
PRIVATE : தனக்கு மட்டும் சொந்தம்

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: