Tuesday, 21 April 2020

SE - 63 - About access specifiers and Access Modifiers

Access Specifiers : public , private , protected , default(package)

Access Modifiers :  final , static , abstract


Apart from normal restrictions and behaviors of above access specifiers let's see some more :

1) A local variable can't be static but it can be final.

2) A variable can never be abstract

3) Overridden method can't be more restrictive than the base class's method

4) A class can't be static (inner class can be static)

5) Interface contains only final variables(constants)

6) Final :
Variable is constant
Method can't be overridden
class can't be inherited

7) Abstract class can have :
All declared methods only
All defined methods only
Declared and defined methods combinations

8) Top level class in Java can't be private or protected or static , only public and default are allowed. Inner class can be private / static.

9) If we declare final static  variable at class level , we can't modify it in any methods.

10) If we declare only static variable at class level , we can modify it in any methods.

11) It is not required to mark a method as abstract. A abstract method is a method without body in abstract class

12) All wrapper class are final



No comments:

Post a Comment