Java Inheritance

Java Inheritance

Inheritance is the process by which a Java class inherits another class content.
A class that inherits another class attributes and behaviors take it.
A private member of a class java can not be inherited.
Class inherited is called the base class or superclass class.
Inheritance is done by using the keyword extends.
The class that performs the extension is called subclass or derived class.
In Java, a class can inherit only one class, but can be inherited by any class.

Inheritance example

public class Test1{  
    int id = 1;
    String name = "Hello Java";
}  

public class Test2 extends Test1{  
    int age = 34;  
    
    public static void main(String args[]){ 
        Test2 ob = new Test2();  
        System.out.println(ob.id+" "+ob.name);  
        System.out.println("Age: "+ob.age);  
    }  
}