Hey guys!! How are you doing!! Welcome to flower brackets blog. Today we will learn abstraction in java.
Abstraction is defined as showing necessary details and hiding the implementation details to the user.
For example, in an ATM machine when user inserts his card a list of ATM services is displayed namely, banking, mini statement, balance enquiry, quick cash, etc. etc.
User doesn’t know what is running behind, what type of programming, functionality involved and where the server is kept by bank so that the data is collected and processed.
So a user is not aware of all these stuffs. Services offered by ATM machine is shown to the user but hiding internal implementation.
We can accomplish abstraction using abstract classes and interface.
Abstract class and abstract methods
- We cannot create instance of an abstract class.
- If a class consists of at least one abstract method then it should be declared as an abstract class.
- “abstract” keyword is used to declare an abstract class.
- An abstract class consists of non-abstract and abstract methods.
- There will be no implementation for an abstract method.
- Subclass should redefine method defined in abstract class. Hence overriding definition of all abstract methods.
- An abstract class also consists of default and parameterized constructor.