Java Abstraction

Java Abstraction

It is a process of hiding implementation details and showing only functionality to the user.

In java we have two types of methods

i) Concrete methods (The methods which are having body)

public void add(){

ii) Abstract methods (The methods which are not having body)


public void add();
if we know the method name, but don't know the method functionality, then we go for abstract methods.

> Java Class contains 100% concrete methods

> Abstract Class contains one or more abstract methods.


Class 1 (having 10 methods)

(10 methods are concrete methods)

It is a Java Class
Class 2 (having 10 methods)

(5 concrete Methods and 5 abstract methods)

Abstract class
Class 3 (having 10 methods)

(10 methods are Abstract methods)

Abstract class
public class HeroHonda extends Bike {

    public void handle() {
        System.out.println("Bikes have handle");
    public void seat() {
        System.out.println("Bikes have Seat");
    public static void main (String [] args){
        HeroHonda obj = new HeroHonda();
Interfaces in Java
> Interface is a Java type definition block which is 100% abstract.

> All the Interface methods are by default public and abstract.

> Static and final modifiers are not allowed for interface methods.

> In Interfaces variables have to initialize at the time of declaration.


int a; // Incorrect

int a = 10; // Correct

> In interfaces variables are public static final by default.

> Interface is going to be used using "implements" keyword.
public class Example2 implements Example1{

    public void add() {

    public void sub() {
public static void main (String [] args){
    Example2 abc = new Example2();
From Class (Concrete Class or Abstract Class) to Class we use "extends" keyword

i) From Concrete Class to Sub class - we can access Super class methods directly.

ii) From Abstract Class to Sub class - Implement all abstract methods then we can access all methods.
From Interface to Class we use "implements" keyword

From Interface to Class - Implement all methods and access.


Post a Comment