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

Java · Theory

Abstraction in Java

← All stacks

Theory

70/270

Abstraction in Java

Abstraction — show what, hide how. abstract class + abstract method = must implement in child.

You cannot write new Shape() if Shape is abstract.

Interface is also abstraction (can-do contract).

Write one tiny example for Abstraction. Compile, print one result, and say the output out loud before you type.

Use Abstraction only when the problem needs it. Don’t force it into every program. Know one beginner trap.

Let's take this on the board with one tiny Main class — no extra files. Abstraction in Java — output: 12.56. Shape has no body for area(); Circle supplies it. new Shape() would not compile. Start from main, go line by line, and stop at each print. That output is the proof for Abstraction.

Exam tip

Say: new Shape() fails; new Circle(2).area() works.

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());
  }
}

Abstraction in Java — output: 12.56. Shape has no body for area(); Circle supplies it. new Shape() would not compile.

Short notes

  • DefAbstraction is a Java idea you should explain with one small example.
  • RuleKnow the keyword / API used for Abstraction. Type a tiny Main and print one result.
  • RememberFor Abstraction, say the output before you code.
  • TrapAbstraction — only memorising the heading. No example, no trap.
  • Hide how, show what
  • abstract class

Questions

1

What is Abstraction?

2

Why do we use Abstraction in Java?

3

Write one small example of Abstraction.

4

What mistake do beginners make with Abstraction?

5

Where is Abstraction used in a real program?

Previous← Difference Between Class and Interface in JavaNextCompile-Time Polymorphism 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.