Example Use Abstract Class
Here the subclass dog provides the implementation for the abstract method makesound.
Example use abstract class. The class contains an abstract method makesound and a non abstract method eat. Class a public. Public static void main string args animal obj new dog.
Example of abstract class that has an abstract method. Virtual void fun 1 0. We have inherited a subclass dog from the superclass animal.
Abstract class example abstract parent class abstract class animal abstract method public abstract void sound. Out of four methods we have an implementation of two methods and we need derived class to implement other two methods. Now coming to an abstract class it is a kind of class that has at least one pure virtual function is known as abstract class in other words if we only declare the function in the base class and doesn t write its implementation in the base class and we use derived classes for writing an implementation of the declared function then that class.
Its implementation is provided by the honda class. In these kind of situations we should use abstract class. Abstract class is used in situation when we have partial set of implementation of methods in a class.
In the above example we have created an abstract class animal.