Access Modifiers In Java

Access Modifiers In Java - private members CAN ONLY access....

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Access Modifiers In Java Access modifiers specifies who can access them. There are four access modifiers used in java. They are public, private, protected, no modifer (declaring without an access modifer). Using ‘no modifier’ is also sometimes referred as ‘package-private’ or ‘default’ or ‘friendly’ access. Usage of these access modifiers is restricted to two levels. The two levels are class level access modifiers and member level access modifiers. I) Class level access modifiers (java classes only) Only two access modifiers is allowed, public and no modifier If a class is ‘public’, then it CAN be accessed from ANYWHERE. If a class has ‘no modifer’, then it CAN ONLY be accessed from ‘same package’. II) Member level access modifiers (java variables and java methods) All the four public, private, protected and no modifer is allowed. public and no modifier – the same way as used in class level.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: private members CAN ONLY access. protected CAN be accessed from same package and a subclass existing in any package can access. Access Control Modifiers: Java provides a number of access modifiers to set access levels for classes, variables, methods and constructors. The four access levels are: 1. Visible to the package. the default. No modifiers are needed. 2. Visible to the class only (private). 3. Visible to the world (public). 4. Visible to the package and all subclasses (protected). Non Access Modifiers: Java provides a number of non-access modifiers to achieve many other functionality. The static modifier for creating class methods and variables The final modifier for finalizing the implementations of classes, methods, and variables. The abstract modifier for creating abstract classes and methods. The synchronized and volatile modifiers, which are used for threads....
View Full Document

This note was uploaded on 02/04/2012 for the course ECON 201 taught by Professor Profatera during the Spring '11 term at Albany Medical College.

Ask a homework question - tutors are online