Abstract class

An abstract class means that nobody can ever make a new instance of that class that means class must be extended.
An abstract class has virtually no use , no value no purpose in life unless it is extended.
Abstract Method:  Abstract method means the method must be overriden. Implementation an abstract method means you are overriding the method.


       abstract class Animal{
                         abstract void eating();
                         abstract void sleeping();

class Dog extends Animal{
                           public void eating()
                                  System.out.println("Dog is eating"); 
                             public void sleeping()
                                      System.out.println("Dog is sleeping");

      class Test{
                public void main(String as[])

                        Animal a =new Dog();


                  Dog is eating
                 Dog is sleeping


  1. When you are unable to create body for the method you must declare method as abstract
  2. When a class contain one or more abstract method then class must be declared as abstract but he reverse is not true i.e no need to have abstract method in abstract class.
  3. We can't create the instance for abstract class but you can declare the reference variable 
  4. When a subclass is extending abstract class then subclass must override all the abstract method otherwise subclass must be declared as "abstract"


Post a Comment