1Sometimes we may come across a situation where we cannot provide
2implementation to all the methods in a class. We want to leave the
3implementation to a class that extends it. In such case we declare a class
4as abstract.To make a class abstract we use key word abstract.
5Any class that contains one or more abstract methods is declared as abstract.
6If we don’t declare class as abstract which contains abstract methods we get
7compile time error.
8
9 1)Abstract classes cannot be instantiated
10 2)An abstarct classes contains abstract method, concrete methods or both.
11 3)Any class which extends abstarct class must override all methods of abstract
12 class
13 4)An abstarct class can contain either 0 or more abstract method.
1An abstract method is the method which does’nt have any body.
2Abstract method is declared with
3keyword abstract and semicolon in place of method body.
4
5 public abstract void <method name>();
6Ex : public abstract void getDetails();
7It is the responsibility of subclass to provide implementation to
8abstract method defined in abstract class
1//abstract parent class
2abstract class Animal{
3 //abstract method
4 public abstract void sound();
5}
6//Dog class extends Animal class
7public class Dog extends Animal{
8
9 public void sound(){
10 System.out.println("Woof");
11 }
12 public static void main(String args[]){
13 Animal obj = new Dog();
14 obj.sound();
15 }
16}