A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

Abstraction in Java

What is the abstraction in Java?

What is the abstraction in Java?

Abstraction is a method, that is hiding of the implementation details and showing only functionality to the user.

Two ways to achieve Abstraction in java:-

  • Abstract class (0 to 100%)

  • Interface (100%)

Abstract class in Java:

A class that is declared as abstract is known as abstract class. You need to keep the abstract keyword with a class. we cannot instantiate or create an object of an abstract class.

Example of Abstract class in Java:-






package oops;

public abstract class Abstract1{
    int div(int x,int y)
    {
        return x/y;
    }
    abstract int mul(int a,int b);
}

class child extends Abstract1
{
   public static void main (String args [])
   {
       int j=20;
       int k=30;
       child c=new child();
       System.out.println(c.mul(j,k));
   }

    @Override
    int mul (int a,int b)
 {
        return a*b;
    }
}


 
Output:

LEARN TUTORIALS

.

.