Inheritance basics

Inheritance is a mechanism in Java that allows you to define a new class based on an existing class. The new class is called the derived class or subclass, and the existing class is called the base class or superclass. The subclass inherits all the members (fields, methods, and nested classes) of the superclass except for its constructors and private members. Inheritance allows you to reuse code and build upon existing code to create new classes.

Syntax

public class Item {
	// Upper class
}

public class Book extends Item {
	// Subclass inherits information from the upper class
}

public class Cd extends Item {
	// Subclass inherits information from the upper class
}