Learn abstraction in java

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

  1. We cannot create instance of an abstract class.
  2. If a class consists of at least one abstract method then it should be declared as an abstract class.
  3. “abstract” keyword is used to declare an abstract class.
  4. An abstract class consists of non-abstract and abstract methods.
  5. There will be no implementation for an abstract method.
  6. Subclass should redefine method defined in abstract class. Hence overriding definition of all abstract methods.
  7. An abstract class also consists of default and parameterized constructor.

Related Posts