PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Java · Theory

Abstract class in Java

← All stacks

Theory

44/270

Abstract class in Java

An abstract class is a partial blueprint. Some methods may be unfinished on purpose. Write abstract class Shape { ... }. You cannot do new Shape() if Shape is abstract.

An abstract method has no body. Children must implement it, unless the child is also abstract. The abstract class can still have normal methods with real code — that shared code is the point.

Use it when related classes share code and a common contract: Circle and Rectangle both extend Shape, both implement area(), both reuse colour(). Instantiating an abstract class with new is the beginner mistake.

Let's take this on the board with one tiny Main class — no extra files. Abstract class in Java — output: 12.56. You cannot write new Shape() — Shape is abstract. new Circle(2) fills in area(). Start from main, go line by line, and stop at each print. That output is the proof for Abstract class.

Diagram
abstract class Shape
    area()   ← no body
    print()  ← real code
         │ extends
         ▼
      Circle implements area()
Exam tip

Abstract class = shared code + forced methods for children.

Example

abstract class Shape {
  abstract double area();
}
class Circle extends Shape {
  double r;
  Circle(double r) { this.r = r; }
  double area() { return 3.14 * r * r; }
}
public class Main {
  public static void main(String[] args) {
    Shape s = new Circle(2);
    System.out.println(s.area());
  }
}

Abstract class in Java — output: 12.56. You cannot write new Shape() — Shape is abstract. new Circle(2) fills in area().

Short notes

  • DefAbstract class = partial blueprint. Some methods may be unfinished.
  • RuleCannot do new on an abstract class. abstract methods have no body.
  • RememberCan still have concrete methods with real code.
  • UseRelated family that shares code + a forced method (Shape → area()).

Questions

1

Can you do new Shape() if Shape is abstract?

2

What is an abstract method?

3

Can an abstract class have concrete methods?

Previous← Java instanceof KeywordNextInterface in java →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.