Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions guide/english/java/data-abstraction/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@ Likewise in Object-oriented programming, abstraction is a process of hiding the

In Java, abstraction is achieved using Abstract classes and interfaces.

Interface is a piece of code defining a set of operations that other code (classes) must implement.
Interfaces were introduced in Java to enhance Java’s single-inheritance model, multiple inheritance created too many problems for programmers and compiler writers.
All methods in interface are public, we may not write it every time, like all of them are abstract, but we never write the key word abstract.
The interface should have at least one method but not too many.

Abstract classes are classes, which should contain at least one abstract method. Note that we can not create instances from abstract class.
We 'extends' an abstract class and we are obligated to implement all of the abstract methods it contains.

Abstract class vs. Interface:
All of the methods in one Interface are abstract, while in abstract class we can have methods with body.
We can implement many interfaces, but we can inherit only one abstract class.

Advantages using interfaces:
It decouples your code.
Helps in team corporation.
Expand Down