Abstraction:
Abstraction is the process of hiding implementation details and showing only the essential features of an object. It tells what an object does but not how it does it.
abstract keyword used to declare abstract class and abstract method.
You cannot create an object of an abstract class.
Uses of abstraction:
Security-Hides unnecessary details from the user.
Simplicity-Focus only on what needs to be done, not how.
Code reusability-Common methods can be reused in abstract classes.
Flexibility-Child classes provide their own implementation.
Maintainability-Changes implementation don't affect end user.
What is final keyword?
The final keyword is a non access modifier in java. It is used to restrict modification of variables, methods and classes.
Final variable(constant):
Once assigned, the value cannot be changed.
Makes a variable a constant.
Final method:
A method declared as final cannot be overridden by child classes.
Used when you want to prevent changing behavior of a method.
Final class:
A class declared as final cannot be inherited (no subclassing).
Uses:
It is used for security, immutability and to prevent misuse of variables, methods and classes.
Top comments (0)