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

Java · Theory

Difference between Abstract Class and Interface in Java

← All stacks

Theory

46/270

Difference between Abstract Class and Interface in Java

This is a favourite interview question, so learn it like a class, not like a slogan. Abstract class = a partial parent in a family. Interface = a can-do contract. Shape is a family: circle and rectangle are shapes. Drawable is a capability: something that can draw. A Circle is a Shape, and it can also be Drawable. That one picture is enough if you can explain it slowly.

You cannot do new Shape() if Shape is abstract. You cannot do new Drawable() on a plain interface. A class extends only one abstract parent. A class can implement many interfaces. Say that first: one parent class, many interfaces. Interviewers wait for that line. Then they ask why.

Why? Abstract class can keep real fields and real methods — colour, x, y, a helper print() that every child reuses. Interface is mainly “you must be able to do this”: draw(), compareTo(). Modern Java has default methods on interfaces, yes. Still don’t say they are the same. Intent is different: family shared code vs capability contract.

Let’s take this on the board. abstract class Animal { abstract void sound(); } interface Pet { void play(); } class Dog extends Animal implements Pet { void sound() { print Bark; } public void play() { print Fetch; } }. Then Dog d = new Dog(); d.sound(); d.play();. Output: Bark then Fetch. Dog is an Animal (IS-A family) and also a Pet (CAN-DO). One tiny program, both ideas.

How to choose in a project. Related types that share code → abstract class. Circle and Rectangle both need colour and area() — Shape. Unrelated types that share an ability → interface. A printer and a screen both can implement Drawable. A car and a bird are not one family. Don’t force Flyable on a car.

Answer with a small table if they ask “difference”: inheritance count, shared code/fields, purpose (IS-A vs CAN-DO), keyword (extends vs implements). Then give Shape vs Drawable. Don’t recite ten Java version notes unless they ask about default methods.

Diagram
Shape   (abstract class)
    colour, area(), print()
         │ extends
         ▼
      Circle
         │ implements
         ▼
  Drawable   (interface)
    draw()

  abstract class = family + shared code
  interface      = can-do contract
Exam tip

Table: one parent vs many interfaces; shared code vs contract; IS-A vs CAN-DO. Then one example: Shape vs Drawable.

Example

abstract class Animal {
  abstract void sound();
}

interface Pet {
  void play();
}

class Dog extends Animal implements Pet {
  void sound() { System.out.println("Bark"); }
  public void play() { System.out.println("Fetch"); }
}

public class Main {
  public static void main(String[] args) {
    Dog d = new Dog();
    d.sound();
    d.play();
  }
}

Difference between Abstract Class and Interface in Java — output: Bark then Fetch. Dog extends Animal (one family, IS-A) and implements Pet (can-do). That is the real difference in one program.

Short notes

  • DefAbstract class = partial parent (family). Interface = can-do contract.
  • RuleOne abstract parent class. Many interfaces. Neither is new’d as a complete object.
  • DiffAbstract class can have fields + real methods. Interface is mainly the API.
  • UseShape family → abstract class. Drawable / Comparable → interface.
  • RememberCircle extends Shape and can also implement Drawable.
  • TrapDon’t say they are identical because of default methods. Intent is still different.

Questions

1

What is the difference between abstract class and interface?

2

How many abstract classes can a Java class extend?

3

How many interfaces can a class implement?

4

When do you pick an abstract class?

5

When do you pick an interface?

6

Can Circle use both?

Previous← Interface in javaNextPackages 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.