Java Inheritance
Java Inheritance
Inheritance is the process by which a Java class inherits another class content.
Inheritance is done by using the keyword extends.
The class that performs the extension is called subclass or derived class.
A java 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); } }