Curriculum
Inheritance and super Keyword in Java are important Object-Oriented Programming concepts used for code reusability and hierarchical relationships between classes. Inheritance allows one class to acquire properties and methods of another class, while the super keyword helps access parent class members.
In this Core Java course in Jaipur, students will learn inheritance in Java, types of inheritance, parent and child classes, method inheritance, constructor inheritance, and the use of super keyword in Java programming.
Inheritance and super keyword are widely used in:
Understanding inheritance and super keyword in Java helps students build scalable and reusable object-oriented applications.
Inheritance in Java is the process where:
Inheritance helps developers:
Inheritance involves:
Example:
Vehicle → Car
Here:
Car inherits:
from Vehicle class.
class Parent {
}
class Child extends Parent {
}
Inheritance is implemented using:
extends
keyword.
class Animal {
void eat() {
System.out.println("Animal is eating");
}
}
class Dog extends Animal {
void bark() {
System.out.println("Dog is barking");
}
public static void main(String[] args) {
Dog d1 = new Dog();
d1.eat();
d1.bark();
}
}
Animal is eating
Dog is barking
Here:
Dog
inherits:
eat()
method from:
Animal
class.
Java mainly supports:
One child class inherits one parent class.
class A {
}
class B extends A {
}
A class inherits another inherited class.
class A {
}
class B extends A {
}
class C extends B {
}
Multiple child classes inherit same parent class.
class A {
}
class B extends A {
}
class C extends A {
}
Java avoids multiple inheritance using classes because it creates:
Instead, Java uses:
The super keyword in Java refers to:
It is used to:
class Animal {
String color = "White";
}
class Dog extends Animal {
String color = "Black";
void display() {
System.out.println(super.color);
}
public static void main(String[] args) {
Dog d1 = new Dog();
d1.display();
}
}
White
class Animal {
void sound() {
System.out.println("Animal Sound");
}
}
class Dog extends Animal {
void sound() {
System.out.println("Dog Barking");
}
void display() {
super.sound();
}
public static void main(String[] args) {
Dog d1 = new Dog();
d1.display();
}
}
Animal Sound
class Animal {
Animal() {
System.out.println("Animal Constructor");
}
}
class Dog extends Animal {
Dog() {
super();
System.out.println("Dog Constructor");
}
public static void main(String[] args) {
Dog d1 = new Dog();
}
}
Animal Constructor
Dog Constructor
Child class can redefine parent methods using:
class Animal {
void sound() {
System.out.println("Animal Sound");
}
}
class Cat extends Animal {
void sound() {
System.out.println("Cat Meowing");
}
}
Inheritance provides:
Parent class:
Account
Child classes:
Parent class:
Person
Child classes:
Parent class:
Product
Child classes:
Without extends:
super can only access parent members.
private variables are not directly accessible in child class.
| Inheritance | Composition |
|---|---|
| IS-A relationship | HAS-A relationship |
| Code reuse through extension | Code reuse through objects |
Understanding inheritance helps students:
In this lesson, students learned:
These concepts are essential for Object-Oriented Programming and Java software development.
Inheritance allows one class to acquire properties and methods of another class.
Inheritance improves code reusability and maintainability.
super refers to parent class object.
Parent class is the class whose properties are inherited.
Java does not support multiple inheritance using classes.
Method overriding allows child class to redefine parent class method.
WhatsApp us