Classes
Access Modifiers
Access modifiers: package-default, public
Non-access modifiers: final, abstract, or none (not obligatory)
Constructors
Access modifiers: private, package-default, protected, public
Non-access modifiers: none are allowed
- No return type allowed.
Blocks
Access modifiers: package-default
Non-access modifiers: static or none
Members
Access modifiers: private, package-default, protected, public
Non-access modifiers: static, final, transient, volatile, synchronized
- If final must be initialized and cannot be volatile.
Methods
Access modifiers: private, package-default, protected, public
Non-access modifiers: static, final, native, strictfp
native:
- Cannot have body code, looks like abstract method e.g. public native void method();
- Must have return type void;
- Cannot be strictfp;
- Can have any other access and non-access modifier type.
Methods cannot be abstract, only abstract classes and interfaces can have abstract methods.
Behaviours
- Can implement one or more interfaces: has to implement all interfaces methods.
- Can extend only one class: inherits methods and members which can be overridden.
- If it extends an abstract class it must implement all abstract methods, unless this class is also abstract. Non-abstract methods and members are inherited.
Leave a Reply