Ads by ProfitSence
Close

is abstract cannot be instantiated

Last Updated on Wednesday 5th Oct 2022

is abstract cannot be instantiated

  • An abstract class is a class that is declared abstract —it may or may not include abstract methods.
  • Abstract classes cannot be instantiated, but they can be subclassed. When an abstract class is subclassed.
  • The subclass usually provides implementations for all of the abstract methods in its parent class

A class is mostly made abstract because it contains some abstract methods. An abstract method is a method that is declared without an implementation.

			
					abstract void draw();

			
	
			
					public abstract class Shape {
  // Notice how we can already add attributes and methods
  private Point origin;

  public Shape(Point origin) {
    this.origin = origin;
  }

   // Declare an abstract draw method
   // (we don't know how to draw this yet => subclass should know)
   abstract void draw();
}

			
	

A class can also be made abstract to force the user of the class to create a subclass from the base class and not allow him/her to directly instantiate objects from the base class.