Java: Basic concept of inheritance

This entry is part 38 of 54 in the series Learn Java

Inheritance is the ability of a class to derive something specific from a generic class.

The generic class is called super class or base class or parent class and the specific class is known as child class or subclass or derived class.

package javaapplication32;

class Book {

    public void print_bk() {
        System.out.println("This is the parent book class");

class LibraryBook extends Book {

    public void print_lbk() {
        System.out.println("This is the library book class");

public class MainBook {

    public static void main(String args[]) {
        Book bk = new Book();
        LibraryBook lbk = new LibraryBook();

In this example, the instance lbk is an instance of LibraryBook.  However, since LibraryBook is a subclass of Book, we are able to use lbk to access the method defined in class Book.


Series Navigation<< Java: Objects as arguments to methods
Java: Calling base class constructor >>