Tuesday, October 13, 2015

Modifier Keywords (Protected, Final, Abstract, Default)

Protected: Protected keyword can be use with variable, methods and constructor. These member only could be accessible to child class in different package and with in the class of same package.

Final: Final keyword can be use with variable, method and class. It behaves different in each case.

Variable: Final Variable could not be re-initializing. It must be initializing at the time of declaration.

Method: Final Method never overrides.

Class: Final class never extends.




Abstract: Abstract keyword can be use with a class and method. When a class defined as abstract, it means the class may have abstract methods or a method, which do not have it body or implementation.

When a class declared as abstract, it’s not necessary that the class has abstract methods. It can contain normal methods. But if, a method declared as abstract then the class must be declared as abstract.


Default: When we are not declaring any modifier with members, compiler automatically declares as default. A method and a variable can be declared as default. But, accessible within same package.


No comments:

Post a Comment

Thank you for your comments.