When a class extend an abstract class it must declare and provide body for each method in the said abstract class. code example

Example 1: abstract class example in java

//abstract parent class
abstract class Animal{
   //abstract method
   public abstract void sound();
}
//Dog class extends Animal class
public class Dog extends Animal{

   public void sound(){
	System.out.println("Woof");
   }
   public static void main(String args[]){
	Animal obj = new Dog();
	obj.sound();
   }
}

Example 2: Is it mandatory for an abstract class to have abstract methods?

No, abstract class can have zero abstract methods.

Tags:

Misc Example