Java Abstraction

Abstraction in java | what is Abstraction in java

Abstraction is the process of hiding the implementation details and showing only functionality to the user.

Another way , it shows only essential things to the user and hides the internal details,

for example , sending sms where you type the text send the message . you don’t know the internal processing about the message delivery .

Abstraction lets you focus on what the object does instead of how it does it.

Ways to achieve Abstraction :-

There are two ways to achieve the abstraction in java

1.Abstract Class(0 to 100%).

2. Interface(100%).

Abstract Class in java :-

A method without body(no implementation) is known as abstract method.

abstract  Class Vehicle(){
   int tyre; 
   abstract void start();
}

If a class has an abstract method,it should be declared abstract as well.
If a Regular class extends in abstract class, then the class must have to implement all the abstract methods of abstract parent class or it has to be declared abstract as well.

A class which is declared as abstract is known as an abstract class.

It can have abstract and non-abstract methods.

It needs to be extended and its method implemented.

It can not be instantiated.

Point to Remember :-

  • An abstract class must be declared with an abstract keyword.
  • It can have abstract and non-abstract methods.
  • It can not be instantiated means we can not create object of abstract class. but we can create reference.
  • It can have constructors and static methods also.
  • It can have final methods within will force the subclass not to change the body of the method.