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

Java · Theory

Inheritance in Java

← All stacks

Theory

33/270

Inheritance in Java

Inheritance lets a child reuse and extend a parent. Keyword: class Dog extends Animal. IS-A idea: Dog is an Animal, so Dog can use parent features.

Java allows one parent class only (single class inheritance). Write common code once in the parent. Special code goes in the child. The child can add new methods and override parent methods.

Deep inheritance trees become hard to change. Keep them shallow. Extra capabilities come from interfaces: one superclass + many interfaces.

Let's take this on the board with one tiny Main class — no extra files. Inheritance in Java — output: Eating then Bark. Dog did not rewrite eat — it inherited it from Animal. Start from main, go line by line, and stop at each print. That output is the proof for Inheritance.

Diagram
Animal
      sound()
        │ extends
        ▼
       Dog
      sound()  →  bark
Exam tip

IS-A + single class inheritance + interfaces for extra contracts.

Example

class Animal {
  void eat() { System.out.println("Eating"); }
}
class Dog extends Animal {
  void bark() { System.out.println("Bark"); }
}
public class Main {
  public static void main(String[] args) {
    Dog d = new Dog();
    d.eat();
    d.bark();
  }
}

Inheritance in Java — output: Eating then Bark. Dog did not rewrite eat — it inherited it from Animal.

Short notes

  • DefInheritance = child reuses and extends parent. Dog extends Animal.
  • RuleIS-A. Java allows one parent class only.
  • RememberCommon code in parent. Special code in child. Child can override.
  • UseOne superclass + many interfaces for extra contracts.

Questions

1

What keyword is used for inheritance?

2

How many parent classes can a Java class have?

3

What does IS-A mean?

Previous← this Keyword in JavaNextAggregation 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.