Abstraction in java example | RealTime achive program

Abstraction is one of the major features of Object Oriented Programming. Abstraction in Java used to show only essential details to the user. Menas hiding an unnecessary internal functionally with users.

For example, a Smart mobile applications only shows to user application and useful function like in Youtube watch videos. Youtube does not show to use how internally it’s connected to the server, downloading videos and codes. User can only interact with the UI of application.

Abstraction in java example RealTime achive program

Definition:- Abstraction is a process of application development to hiding the implementation details from the user. Оnly the user useful functionality will be provided to the user. Java Abstraction is achieved by using abstract classes and interfaces.

How to achive Abstraction in Java Example

There are two ways to achieve abstraction in java.

  • Abstract class (0 to 100%)
  • Interface (Achieve 100% abstraction)

Before see the example of Abstraction you have to know about few things.

Let’s see the simple Java abstraction example program code.

Abstraction in Java Example

In the example have a Bank abstract class. Then there are 2 more classes represent the banks with there interest rate method.

What are some real-time examples Abstraction in Java?

Answer:- Let’s see the some example of real time abstractions:-

  • Vehicle (car/bike) – You can do riding a bike or driving a car without knowledge about hows it works.
  • ATM Machine – It’s every day used machine. Here you can do cash withdrawal, money transfer, check bank balance, etc. But you don’t know hows internally implementations have done and work.

Types of abstraction

Typically abstraction can be seen in two ways:

  • Data abstraction
  • Control abstraction

Abstraction with Interface

An abstract class can also use to provide an implementation of the interface. Using an interface forced to implement all methods. See below example:-

How to Abstract class having constructor, data member and methods?

You can use data member, abstract method, method body (non-abstract method), constructor, and even main() method in the abstract class. Like the below example.

Do comment if you have any doubt or suggestion on this tutorial.

Note: This example (Project) is developed in IntelliJ IDEA 2018.2.6 (Community Edition)
JRE: 11.0.1
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.14.1
Java version 11
All Java abstraction Examples are in Java 11, so it may change on different from Java 9 or 10 or upgraded versions.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.