Abstract classes & Methods in Java

Specifying a class with keyword abstract indicates that it can’t be instantiated. You can create the instance of the class by using new operator. Suppose you want to write a super class wherein certain methods are implemented and some methods are abstract methods (just method signatures without any implementation ). Point to be noted about abstract classes and methods are as follow:

  • To define an abstract class keyword abstract must be used
  • An abstract class can’t be instaniated
  • An abstract method can’t be contained in a non-abstract class
  • If an abstract classes is extended in a non-abstract sub class, all the abstract methods must be implemented
  • A class that contains abstract methods must be defined abstract
  • An abstract class can’t be instaniated using the new operator but still constructors can be defined which are invoked by its sub classes
  • It is possible to define a class abstract with no abstract methods
  • A subclass can be abstract even if its superclass is concrete
  • A sub class can override a method from its super class to define it abstract
  • You can’t create the instance of an abstract class but it can be used as data type

Example 1

Example 2

No Responses