Course Content‎ > ‎Session 5‎ > ‎

Abstract Methods and Classes

By making a method final, we ensure that the method is not redefined in the subclass. This means that the method can never be subclassed. But in Java, we can also define methods that must always be redefined in a subclass, thus making overriding compulsory. This is done, by using the modifier keyword abstract in the method definition. For example, here is an abstract class Shape
    abstract class Shape
        abstract void draw( );

When a class contains one or more abstract methods, it should be declared as abstract. Following points have to be considered, before using abstract classes. We cannot use abstract classes to instantiate objects directly.  For example,
    //illegal declaration, Shape is an abstract class    
    Shape s = new Shape(); 

The abstract methods of an abstract class must be defined in its subclass. We cannot declare abstract constructors or abstract static methods.