If we have a class, e.g.,
OrigClass
, and we want to make a new class that has many of the same features, we may be able to make a subclass of the original class.Subclass: A subclass extends another class (known as its superclass). The syntax is:public class Subclass extends OrigClass { ⋮ }A subclass
- inherits all the superclass's instance variables (its state)
- inherits all the superclass methods
- may include additional instance variables and methods
- may redefine/override some methods
Subclass code may directly access all inherited instance variables and methods that are public or protected (but not private).