Data abstraction is a method where essential elements are displayed to the user and trivial elements are kept hidden.
In Java, abstraction is achieved by using the abstract
keyword for classes and interfaces. In abstract classes, we can have abstract methods as well as concrete methods.
The following piece of code shows abstraction in Java:
// Abstraction in Javaabstract class ElectricityBill{//abstract methodabstract float computeBill();}class Commercial extends ElectricityBill{@Overridefloat computeBill() {return 1.25*100;}}class Domestic extends ElectricityBill{@Overridefloat computeBill() {return 0.25*75;}}