Single inheritance in Java is when one child class extends exactly one parent class using the extends keyword. The child class inherits all accessible fields and methods from the parent. It is the simplest form of inheritance in Java, fully supported by the language, and the most commonly used in both university lab programs and real-world applications.
- Single inheritance means one child class extends exactly one parent class, nothing more.
- The extends keyword is all you need in Java to set up the relationship.
- The child class inherits all non-private fields and methods from the parent.
- Java does not support multiple inheritance with classes, but single inheritance in Java is fully supported and widely used.
- This concept appears in university exams, job interviews and real production code alike.
What Single Inheritance in Java Is
Single inheritance in Java describes a class hierarchy where one subclass derives from one superclass. The subclass gets access to the superclass’s accessible fields and methods, and it can also define its own. Think of it like a child inheriting traits from one parent, not two.
According to the Oracle Java Documentation, a subclass inherits all the public and protected members of its parent class, regardless of the package the subclass is in. Private members are not inherited directly, though they can be accessed through public getters and setters.
The JetBrains State of Developer Ecosystem 2023 report found that Java is used by 48% of professional developers surveyed globally, making single inheritance in Java one of the most practically relevant OOP concepts a student can learn.
Key Terms You Need to Know
| Term | Meaning | Java Keyword |
|---|---|---|
| Parent class (Superclass) | The class whose properties are inherited | class ParentName |
| Child class (Subclass) | The class that inherits from the parent | extends |
| Method reuse | Calling a parent method directly from the child | super (optional) |
| Method overriding | Child redefines a parent method | @Override |
| Constructor chaining | Child constructor calls parent constructor | super() |
Is Single Inheritance the Same as Simple Inheritance?
Yes, single inheritance and simple inheritance refer to the same concept. Some textbooks and university syllabi in India, particularly under Osmania University and Mumbai University curricula, use “simple inheritance” as an alternate term. Both mean exactly one parent and one child class, with no branching. AICTE-affiliated engineering colleges across India include single inheritance in Java as a core topic in their first and second year OOP lab syllabus.
Where Is Single Inheritance in Java Used?
You will see single inheritance in Java everywhere in Java-based systems. A SavingsAccount class extending a generic BankAccount class is a classic real-world example used by banking software built on Java EE. Android app development, which is Java-based at its core, uses single inheritance in Java constantly when custom Activity classes extend Android’s built-in AppCompatActivity.
The Stack Overflow Developer Survey 2024 shows Java ranked among the top 5 most used programming languages by professional developers globally, which means inheritance patterns like single inheritance in Java are in active production use every day, not just in textbooks.
According to the TIOBE Index for 2024, Java consistently ranks in the top 3 programming languages worldwide, and single inheritance in Java remains one of the first OOP concepts tested in campus placements at companies like TCS, Infosys and Wipro. NASSCOM data shows Java developer roles account for a significant share of IT job postings on Indian platforms like Naukri.com each year.
Program to Implement Single Inheritance in Java
Here is a clean, exam-ready single inheritance program in Java. This is structured the way a lab record should look, with a clear class hierarchy and a main method to run everything.
Copy this exactly, save it as Main.java, compile with javac Main.java and run with java Main. If you are new to compiling from the terminal, the same compile-and-run logic applies here as when you how to write, compile and run a C program, just with different commands.
// Parent class
class Animal {
String name = "Dog";
void eat() {
System.out.println(name + " is eating.");
}
void sleep() {
System.out.println(name + " is sleeping.");
}
}
// Child class inheriting from Animal — single inheritance in Java
class Dog extends Animal {
void bark() {
System.out.println(name + " is barking.");
}
}
// Main class to test the program
public class Main {
public static void main(String[] args) {
Dog d = new Dog();
d.eat(); // inherited from Animal
d.sleep(); // inherited from Animal
d.bark(); // defined in Dog
}
}
Expected Output
When you compile and run this single inheritance in Java example, you will see this output in your terminal:
- Dog is eating.
- Dog is sleeping.
- Dog is barking.
The first two lines come from methods defined in the Animal parent class. The third line comes from the Dog child class. The child object can call all three methods because of single inheritance in Java.
Line-by-Line Explanation and Output
Let us break down exactly what each part of the program does. This is the section you want to study before a viva or practical exam.
The Parent Class: Animal
class Animal declares the superclass. It has one field, name, set to “Dog”. It has two methods, eat() and sleep(), which print simple messages. There is no constructor defined here, so Java uses its default no-argument constructor automatically.
The field name is package-level accessible (no access modifier), which means the child class in the same package can read it directly. In production code, you would typically make this private and provide a getter, but for a lab program this is clean and clear.
The Child Class: Dog
class Dog extends Animal is the line that establishes single inheritance in Java. The keyword extends tells the Java compiler that Dog is a subclass of Animal. From this point, every object of type Dog automatically has access to name, eat() and sleep().
The bark() method is defined only in Dog. An Animal object cannot call bark(), but a Dog object can call everything. This is the direction of inheritance in single inheritance in Java: downward from parent to child, never the other way. This IS-A relationship is the foundation of the concept — a Dog IS-A Animal, so it inherits Animal’s behaviour.
The Main Method
Dog d = new Dog(); creates an instance of the child class. When you call d.eat(), Java looks for eat() in Dog first, does not find it there, then moves up to Animal and executes it. This lookup chain is called the method resolution order.
This is why single inheritance in Java works cleanly: there is only one parent to look up to, so there is never ambiguity. Java deliberately avoided multiple class inheritance to prevent the “diamond problem” that C++ developers deal with. Note also that every class in Java implicitly extends the Object class, making Object the root superclass of all Java classes.
Common Mistakes Students Make
One mistake seen frequently in lab submissions: students try to access a private field of the parent class directly in the child class and get a compile-time error. Private members are not inherited in the accessible sense. Use protected or provide a getter method in the parent.
Another common error is calling a method that exists only in the child class on a parent-type reference variable. If you write Animal d = new Dog(); and then try d.bark();, the compiler will throw an error because the Animal type does not know about bark(). You would need to cast it. For a deeper look at what can go wrong at runtime, the guide on Java exceptions and common runtime errors covers ClassCastException and related issues well.
Practical Tip for Lab Records
Always include the AIM, ALGORITHM and OUTPUT sections in your lab record. For this program, your aim would be “To implement single inheritance in Java using the extends keyword.” Examiners at Indian universities check whether students understand the flow, not just whether the code compiles.
If you are preparing for open-book or practical exams, the approach covered in this guide on open book exams and how to prepare will help you structure your answers efficiently under time pressure.
Exam Tips and Interview Notes for Single Inheritance in Java
What Examiners Actually Ask
University examiners and technical interviewers do not just want to see the code. They want to know you understand the concept. Expect questions like: “What happens if you do not use extends?”, “Can a child class have its own constructor?”, and “What is the difference between single inheritance and multilevel inheritance in Java?”
Knowing single inheritance in Java cold gives you a genuine edge in campus placements at companies like TCS, Infosys, Wipro and product startups, where OOP fundamentals are tested in the first technical round.
What Is the Difference Between Single Inheritance and Multilevel Inheritance in Java?
In single inheritance in Java, one child class extends one parent class directly. In multilevel inheritance, the chain extends further: class A extends class B, and class B extends class C, creating a three-level hierarchy. Single inheritance in Java is simpler and easier to debug; multilevel inheritance is used when you need progressively specialised behaviour across multiple levels.
Quick Comparison: Single vs Other Inheritance Types in Java
| Inheritance Type | Supported in Java? | Description |
|---|---|---|
| Single | Yes | One child extends one parent |
| Multilevel | Yes | A extends B, B extends C |
| Hierarchical | Yes | Multiple children extend one parent |
| Multiple (classes) | No | Java does not allow this; use interfaces instead |
| Hybrid | Partial | Supported only via interfaces, not classes |
What to Know for Your Next Career Step
If you are a BSc CS or BCA student wondering where single inheritance in Java fits in your overall degree, the article on BSc Computer Science subjects and scope shows how OOP with Java connects to data structures, software engineering and beyond. And if you are an MCA student thinking about placements, the breakdown of jobs and salary after MCA is worth reading before your final semester.
Understanding single inheritance in Java also matters beyond academics. Secure coding practices in Java, which are tested in certifications like CEH v13, rely on understanding how objects and classes relate to each other. You cannot write safe, well-structured code without a firm grip on OOP fundamentals.
Before writing your first full Java project, it also helps to know which software development tools to learn first, including IDEs like IntelliJ IDEA and Eclipse that make working with class hierarchies much easier than a plain text editor.
Wrapping this up: single inheritance in Java is the foundation of object-oriented design. Once you can write it, explain it and trace its output confidently, you are ready to tackle multilevel inheritance, interfaces and polymorphism. Here are three things to do this week:
- Write the Animal-Dog single inheritance in Java program from scratch without looking at this page, then add a third method in the child class that also calls a parent method using super.
- Modify the program so the parent field is private and access it through a getter method; observe the compile error first, then fix it.
- Explore 3.0 University’s 3.0 University online certification courses if you want to move from Java fundamentals into ethical hacking, AI or blockchain. Strong OOP skills are the real starting point for the CEH v13 AI online course, where you will write and analyse code in actual security scenarios.
Frequently Asked Questions
What is single inheritance in Java?
Single inheritance in Java is when one subclass extends exactly one superclass using the extends keyword. The child class inherits all accessible fields and methods from the parent. It is the simplest form of inheritance and the most commonly used in Java programs and lab exercises across BTech, BCA, BSc CS and MCA courses in India.
How do I write a single inheritance program in Java?
Create a parent class with fields and methods, then create a child class using class ChildName extends ParentName. In your main method, create an object of the child class and call both parent and child methods on it. Save the file as the name of your public class, compile with javac and run with java.
What is the output of a single inheritance example in Java?
In the Animal-Dog example above, the output is “Dog is eating.”, “Dog is sleeping.” and “Dog is barking.” The first two lines come from inherited parent methods and the third from the child’s own method. The output order matches the order in which you call the methods in main.
Is single inheritance the same as simple inheritance?
Yes, single inheritance and simple inheritance are the same thing. Both terms describe one child class inheriting from one parent class. Some Indian university syllabi and older textbooks prefer the term “simple inheritance,” but the concept, syntax and output are identical.
What is the difference between single inheritance and multilevel inheritance in Java?
Single inheritance in Java involves one child class extending one parent class directly. Multilevel inheritance involves a chain: class C extends class B, which itself extends class A. Single inheritance is simpler and has no chain; multilevel inheritance creates a hierarchy of three or more levels. Both are fully supported in Java.
Where is single inheritance in Java used in real projects?
Single inheritance in Java is used constantly in Android development (custom Activity classes extend AppCompatActivity), in Java enterprise applications (domain classes extend base entity classes) and in framework design. Any time you want to specialise a general class without duplicating its code, single inheritance in Java is the right tool.
Last updated: June 2025. Reviewed by the 3University editorial team.