Inheritance In Java:

Inheritance in java is one of the key features of OOP that allows us to create a new class from an existing class. The new class that is created is known as subclass (child or derived class) and the existing class from where the child class is derived is known as superclass (parent or base class).

Here are the different types of inheritance in Java:

  • Single Inheritance: In Single Inheritance one class extends another class (one class only). …
  • Multiple Inheritance:
  • Multilevel Inheritance:
  • Hierarchical Inheritance:
  • Hybrid Inheritance:
class Base{
    private int id;
    String name;

    public void setId(int id) { = id;

    public int getId() {
        return id;

    public void setName(String name) { = name;

    public String getName() {
        return name;

class Derived extends Base{
    int salary;

    public void setSalary(int salary) {
        this.salary = salary;

    public int getSalary() {
        return salary;
public class tut10 {
    public static void main(String[] args) {
        Derived d1 = new Derived();
        Base b1 = new Base();

Leave a Reply

For News Subscribe Us!

Can curiosity may end shameless explained. True high on said mr on come. An do mr design at little myself wholly entire though. Attended of on stronger or mr pleasure.

You have been successfully Subscribed! Ops! Something went wrong, please try again.

© 2022 Code With AM