ABSTRACT CLASS AND METHOD IN JAVA PROGRAMMING

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

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center