This is a Java Program to Illustrate Use of All Features of Abstract Class.
Sometimes you will want to create a superclass that only defines a generalized form that will be shared by all of its subclasses, leaving it to each subclass to fill in the details. Such a class determines the nature of the methods that the subclasses must implement.
Here is the source code of the Java Program to Illustrate Use of All Features of Abstract Class. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
abstract class Operations
{
float a = 12, b = 6, c;
abstract void add();
void subtract()
{
c = a - b;
System.out.println("Result:"+c);
}
abstract void multiply();
void divide()
{
c = a / b;
System.out.println("Result:"+c);
}
}
public class Abstract_Demo extends Operations
{
@Override
void add()
{
c = a + b;
System.out.println("Result:"+c);
}
@Override
void multiply()
{
c = a * b;
System.out.println("Result:"+c);
}
public static void main(String[] args)
{
Abstract_Demo obj = new Abstract_Demo();
obj.add();
obj.subtract();
obj.multiply();
obj.divide();
}
}
Output:
$ javac Abstract_Demo.java $ java Abstract_Demo Result:18.0 Result:6.0 Result:72.0 Result:2.0
Sanfoundry Global Education & Learning Series – 1000 Java Programs.
advertisement
Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.
Related Posts:
- Practice Information Technology MCQs
- Check Programming Books
- Practice BCA MCQs
- Apply for Computer Science Internship
- Apply for Java Internship