Java Program to Illustrate Use of All Features of Abstract Class

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.

  1. abstract class Operations
  2. {
  3.     float a = 12, b = 6, c;
  4.     abstract void add();
  5.     void subtract()
  6.     {
  7.         c = a - b;
  8.         System.out.println("Result:"+c);
  9.     }
  10.     abstract void multiply();
  11.     void divide()
  12.     {
  13.         c = a / b;
  14.         System.out.println("Result:"+c);
  15.     }
  16. }
  17. public class Abstract_Demo extends Operations
  18. {
  19.     @Override
  20.     void add()
  21.     {
  22.         c = a + b;
  23.         System.out.println("Result:"+c);
  24.     }
  25.     @Override
  26.     void multiply()
  27.     {
  28.         c = a * b;
  29.         System.out.println("Result:"+c);
  30.     }
  31.     public static void main(String[] args)
  32.     {
  33.         Abstract_Demo obj = new Abstract_Demo();
  34.         obj.add();
  35.         obj.subtract();
  36.         obj.multiply();
  37.         obj.divide();
  38.     }
  39. }

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
advertisement

Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.