Abstraction and Interface in Java


--Abstraction is a process of hiding the implementation details and showing only functionality to the user.
--In Abstraction only the essential details are displayed to the user. The trivial or the non-essentials units are not displayed to the user. Ex: A car is viewed as a car rather than its individual.
--There are two ways to achieve abstraction in java
1. Abstract class (0 to 100%)
2. Interface (100%)

Abstract Class:

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.
An abstract class must be declared with an abstract keyword.
Abstract Class can have abstract and non-abstract methods.
Abstract class cannot be instantiated.
Abstract class can have constructors final and static methods also.
Abstract class can have final methods
If there is an abstract method in a class, that class must be abstract.


--An interface in java is a blueprint of a class. It has static constants and abstract methods.
--There can be only abstract methods in the Java interface, not method body. It is used to achieve abstraction and multiple inheritance in Java.
--It cannot be instantiated just like the abstract class.
--In interface we can have default and static methods.
--In interface we can have private methods.

Class and Interface Relationships:

Class and Interface in Java

Class and Interface Relationships

Why we use Interface?

--It is used to achieve abstraction.
--By interface, we can support the functionality of multiple inheritance.

Multiple inheritance in Java by interface:

--If a class implements multiple interfaces, or an interface extends multiple interfaces, it is known as multiple inheritance.
--Multiple inheritance is not supported through class in java, but it is possible by an interface,

Multiple Inheritance in Java

Abstract Class Vs Interface

Difference between Abstract Class and Interface
Difference between Abstract Class and Interface

To get more details please watch below youtube video and Subscribe the channel.

No comments:

Post a Comment