Abstract Classes

      An Abstract class is the one that consists of both abstract as well as concrete methods. Even if a class have only one abstract method, we declare that class as abstract class. The following is the example of abstract class.

Abstract Class Example
Fig1: Abstract Class Example
        In the above example we have one abstract method as well as one concrete method in a class, so we have declared that class as Abstract. All abstract classes does not contain abstract methods. We can declare a class as abstract even if it contains no abstract methods. The following is the example of such class.

Abstract Class without abstract methods
Fig2: Abstract Class without abstract methods

       We cannot create an object to the abstract class, but we can create a reference variable which can hold the object of the class that inherits its properties. If we are trying to inherit the properties of an abstract class, we must provide the implementation to all the abstract methods of that class, if any.                               
                

No comments:

Post a Comment