Class members means methods and instance (nonlocal) variable. If a class cannot be accessed, its members cannot be accessed.
For class members, access means:
- Can access a member of anotehr class.
- Can inherit a member of it superclass.
Class members have four access control level:
Can be accessed by all other classes, even in other package.
Can be accessed only by code in the same class.
Not visible to sublcass, so private members cannot be inherited.
For best practice, instance variable must be mark by private. There can be access by methods (mark by public).
protected and default
Default members can be acces only by classes in the same package.
protected members can be accessed by other classes in the same package, plus subclasses regardless of package.
For subclasses outside the package, the protected member can be access only through inheritance.
A protected member inherited by subclass from another package is not accessible to any other class in the subclass package, except for the subclass own subclasses.
Local variables declaration cannot have access modifier. The only one modifier is final. They don’t get default value, you must initialized before use.
Nonaccess member modifier (method)
Final method cannot be overrided in a subclass.
An abstract method is a method that’s been declared (as abstract) but not implemented.
If a single method is mark by abstarct, the whole class must be declared abstract.
The firts nonabstract (concrete) class to extend the abstract class must implement all of the abstract class abstract method.
The synchronized method indicates that a method can be accessed by only one thread at the time.
The native modifier indicates that a method is implemented in platform-dependent code, often in C.
Force floating points (and any floating points operations) to adhere to the IEEE 754 standard. With strictfp, you can predict how your foalting points will behave regardless of the underlying platform the JVM is running on.
Nonaccess member modifier (variables)
This keyword makes it imposible to reinitialize that variable once it has been initialized with an explicit value.
Tell the JVM to skip this variable when you attempt to serialize the object containing it.
Can be apply only to instance variable.
Tell the JVM that a thread accessing the variable must always reconcile its own private copy of the variable with the master on the memory.