ABSTRACT CLASS AND METHOD IN JAVA PROGRAMMINGsteemCreated with Sketch.

in Freewriters4 years ago

Abstraction is yet another important aspect of object oriented programming language. Think it as a really simple example, you might have send message from facebook to your friend, you just have to type text and then click send. You don't know the internal mechanism of how message is being sent. Abstraction means the same hiding details and showing only useful functionality to the user. This program is a simple demonstration of abstract class and method in java. There are two things that need to be kept in mind. First we can't create object of an abstract class and second the abstract method must be inside the abstract class.

package Polymorphism;

abstract class sum{
    public abstract void displaysum();
}

class sumoftwonumber extends sum{
    public void displaysum() {
        System.out.println("Sum has been displayed");
    }
}

public class AbstractClass {

    public static void main(String[] args) {
        sum obj=new sumoftwonumber();
        obj.displaysum();
    }

}


Here's the output of the above code.


Screenshot_3.png

Coin Marketplace

STEEM 0.20
TRX 0.15
JST 0.029
BTC 64401.36
ETH 2627.01
USDT 1.00
SBD 2.83