0% found this document useful (0 votes)
4 views3 pages

Inheritance_Java_Notes

Inheritance in Java is a fundamental concept of Object-Oriented Programming where a child class inherits fields and methods from a parent class, promoting code reusability and simplifying code hierarchy. Java supports single, multilevel, and hierarchical inheritance, but not multiple or hybrid inheritance directly. Method overriding allows a child class to provide a specific implementation of a method already defined in its parent class.

Uploaded by

diwof34180
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Inheritance_Java_Notes

Inheritance in Java is a fundamental concept of Object-Oriented Programming where a child class inherits fields and methods from a parent class, promoting code reusability and simplifying code hierarchy. Java supports single, multilevel, and hierarchical inheritance, but not multiple or hybrid inheritance directly. Method overriding allows a child class to provide a specific implementation of a method already defined in its parent class.

Uploaded by

diwof34180
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Inheritance in Java - Notes

Inheritance in Java

What is Inheritance?

Inheritance is a key concept of Object-Oriented Programming (OOP) where one class (child) inherits fields

and methods from another class (parent).

Why Use Inheritance?

- Code Reusability

- Avoids Duplication

- Enables Method Overriding

- Simplifies Code Hierarchy

Syntax:

class Parent {

// parent methods and properties

class Child extends Parent {

// child inherits from parent

Example:

class Animal {

void eat() {

System.out.println("I can eat");

class Dog extends Animal {

void bark() {
Inheritance in Java - Notes

System.out.println("I can bark");

Types of Inheritance in Java:

1. Single Inheritance -> Supported

2. Multilevel Inheritance -> Supported

3. Hierarchical Inheritance-> Supported

4. Multiple Inheritance -> Not supported directly (Java avoids diamond problem)

5. Hybrid Inheritance -> Not supported directly

Method Overriding:

class Animal {

void sound() {

System.out.println("Some sound");

class Dog extends Animal {

@Override

void sound() {

System.out.println("Dog barks");

Real-world Example:

class Employee {

String name;

void work() {

System.out.println(name + " is working");

}
Inheritance in Java - Notes

class Manager extends Employee {

void manage() {

System.out.println(name + " is managing team");

Notes:

- Use 'extends' keyword for inheritance.

- Private members of parent class are not directly accessible.

- Constructors are not inherited but can be accessed using super().

You might also like