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.

advertisement
  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

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

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!
advertisement
advertisement
advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn