Inheritance of java &types

Java Inheritance is a fundamental concept in OOP(Object-Oriented Programming). It is the mechanism in Java by which one class is allowed to inherit the features(fields and methods) of another class. In Java, Inheritance means creating new classes based…


This content originally appeared on DEV Community and was authored by Rajan S

Java Inheritance is a fundamental concept in OOP(Object-Oriented Programming). It is the mechanism in Java by which one class is allowed to inherit the features(fields and methods) of another class. In Java, Inheritance means creating new classes based on existing ones. A class that inherits from another class can reuse the methods and fields of that class

types of inheritance

Single Inheritance
Multilevel Inheritance
Hierarchical Inheritance
Multiple Inheritance
Hybrid Inheritance
  1. Single Inheritance

class vehicle{

void bike()
{
    System.out.println("bike comfort for two person");
}

}

class car extends vehicle {

void red()
{
    System.out.println("car comfort for four person");
}

}

public class Single {
public static void main(String args[]) {

car c1 = new car ();

c1.bike();
c1.red();

}

}

Output

bike comfort for two person
car comfort for four person

  1. Multilevel Inheritance

class vehicle{

void bike()
{
    System.out.println("bike comfort for two person");
}

}

class car extends vehicle {

void red()
{
    System.out.println("car comfort for four person");
}

}

class bicycle extends car {

void black ()
{
    System.out.println("i like so much");
}

}

public class Multilevel {

public static void main(String args[]) {

bicycle b1 = new bicycle();

b1.bike();
b1.red();
b1.black();

}

}

output

bike comfort for two person
car comfort for four person
i like so much

  1. Hierarchical Inheritance

class vehicle{

void bike()
{
    System.out.println("bike comfort for two person");
}

}

class car extends vehicle {

void red()
{
    System.out.println("car comfort for four person");
}

}

class van extends car {

void white ()
{
    System.out.println("van comfort in more person");
}

}

public class Hierarchical {

public static void main(String args[]) {

van v1 = new van();

v1.bike();
v1.red();
v1.white();

}

}

output

bike comfort for two person
car comfort for four person
van comfort in more person


This content originally appeared on DEV Community and was authored by Rajan S


Print Share Comment Cite Upload Translate Updates
APA

Rajan S | Sciencx (2025-08-29T10:44:17+00:00) Inheritance of java &types. Retrieved from https://www.scien.cx/2025/08/29/inheritance-of-java-types/

MLA
" » Inheritance of java &types." Rajan S | Sciencx - Friday August 29, 2025, https://www.scien.cx/2025/08/29/inheritance-of-java-types/
HARVARD
Rajan S | Sciencx Friday August 29, 2025 » Inheritance of java &types., viewed ,<https://www.scien.cx/2025/08/29/inheritance-of-java-types/>
VANCOUVER
Rajan S | Sciencx - » Inheritance of java &types. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/08/29/inheritance-of-java-types/
CHICAGO
" » Inheritance of java &types." Rajan S | Sciencx - Accessed . https://www.scien.cx/2025/08/29/inheritance-of-java-types/
IEEE
" » Inheritance of java &types." Rajan S | Sciencx [Online]. Available: https://www.scien.cx/2025/08/29/inheritance-of-java-types/. [Accessed: ]
rf:citation
» Inheritance of java &types | Rajan S | Sciencx | https://www.scien.cx/2025/08/29/inheritance-of-java-types/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.