A Developer Gateway To IT World...

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

Example of abstract class in abstraction

/*
abstraction has two way in java
<1.> abstract class, 
<2.> interface
*/

//abstract class
abstract class Student
{
    //abstract method
    abstract int add(int x, int y);
   
    //non-abstract method
    int sub(int x, int y)
    {
        return x-y;
    }
}
class Calc extends Student
{
    //implementing all abstract method
    int add(int x, int y)
    {
        return x+y;
    }
   
    public static void main(String args[])
    {
        //note: we can't make object of abstract class
        Calc  obj = new Calc();
        System.out.println(obj.add(10, 5));
        System.out.println(obj.sub(10, 5));
    }

}

LEARN TUTORIALS

.

.