Inheritance Introduction
In the Java language, classes can be derived from other classes, thereby inheriting fields and methods from those classes.
A class that is derived from another class is called a subclass (also a derived class, extended class, or child class). The class from which the subclass is derived is called a superclass (also a base class or a parent class).
Inheritance Basics
To inherit a class, you simply incorporate the definition of one class into another by using the extends keyword. Consider a single example :
class first { public void function1() { System.out.println("Inside Base Class"); } } public class SimpleInheritance extends first { // extends is used to inherit // elements from first class to // second class /* function1() is also present here, but not visible */ public void function2() { System.out.println("Inside Derived Class"); } public static void main(String[] args) { SimpleInheritance object1 = new SimpleInheritance(); object1.function1(); // calling base class function1 object1.function2(); // calling present class function2 } }