This is a Java Program to Illustrates Use of Abstract Class and Method.
Here we made add() and multiply() as abstract methods in parent class which are defined in child class and we can call all these mehods via making object of child class.
Here is the source code of the Java Program to Illustrates Use of Abstract Class and Method. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
abstract class Calculation
{
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 AbstractionDemo extends Calculation
{
void add()
{
c = a + b;
System.out.println("Result:"+c);
}
void multiply()
{
c = a * b;
System.out.println("Result:"+c);
}
public static void main(String[] args)
{
AbstractionDemo obj = new AbstractionDemo;
obj.add();
obj.subtract();
obj.multiply();
obj.divide();
}
}
Output:
$ javac AbstractionDemo.java $ java AbstractionDemo 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]Related Posts:
- Practice BCA MCQs
- Check Programming Books
- Apply for Computer Science Internship
- Practice Information Technology MCQs
- Apply for Java Internship