Java OOPS – Part 3 – Data abstraction with examples

Abstraction is method of hiding the implementation details and showing only the functionality, basicallyProvides guidelines to build a standard product.

Example –

You know how a car look like and how to drive, but you don’t know how to build a car.

For detailed explanation –

Types of abstraction –

Abstraction can be achieved by 2 types

  • Abstract
  • Interface

Abstract –

  • Abstract class will have mix of implemented and un implemented methods
  • Syntax – abstract class ClassName
  • An abstract class may or may not contain abstract methods
  • If at least one method is abstract, then the class should be declared as abstract
  • Can not create an object of an Abstract class
  • Child class that inherit abstract class with abstract methods, should implement all the abstract methods
  • Abstract class can have constructors

Code implementation –



Interface –

  • Interface should have all unimplemented methods.
  • Syntax – interface InterfaceName
  • All the methods in interface are abstract
  • Can not create an object of an interface
  • All the fields of an interface must be declared as static final
  • An interface is implemented by a class
  • An interface is extended by multiple interface

Code implementation – 


Content posted is based on learning or working experience,
Share the post with others if find useful,
Any queries?, leave comments or discuss on our, Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *