Inheritance
§A form of software reuse in which a new class is created by absorbing an existing class’s members and embellishing them with new or modified capabilities.
§Can save time during program development by basing new classes on existing proven and debugged high-quality software.
§Increases the likelihood that asystem will be implemented and maintained effectively.
}When creating a class, rather than declaring completely new members, you can designate that the new class should inherit the members of an existing class.
§Existing class is the superclass
§Newclass is the subclass
}Each subclass can be a superclass of future subclasses.
}Asubclass can add its own fields and methods.
}A subclass is more specific than its superclass and represents a more specialized group of objects.
}The subclass exhibits the behaviors of its superclass and can add behaviors that are specific to the subclass.
§This is why inheritance is sometimes referred to as specialization.
}The directsuperclass is the superclass from which thesubclass explicitly inherits.
}An indirectsuperclass is any class above the directsuperclass in the class hierarchy.
}The Java class hierarchy begins with class Object (in package java.lang)
§Every class in Java directly or indirectly extends (or “inherits from”) Object.
}Java supports only single inheritance, in which each class is derived from exactly one direct superclass.
}We distinguish between the is-a relationship and the has-a relationship
}Is-a represents inheritance
§In an is-a relationship, an object of a subclass can also be treated as an object of its superclass
}Has-a represents composition
§In a has-a relationship, an object contains as members references to other objects
.

