next up previous
Next: Inheritance: example Up: Unit 03 Previous: Example for the design

Inheritance

Inheritance in object-oriented languages consists in the possibility of defining a class that is the specialization of an existing class: i.e., defining a class that has the same properties as an already existing class, but to which we want to add new functionalities and/or new information.

Instead of modifying the already defined class, we create a new class derived from it. For example:

public class Student extends Person {
  ...
}

We say that:

A subclass inherits all the methods and all the instance variables of the superclass, and additionally it can have its own methods and instance variables.


next up previous
Next: Inheritance: example Up: Unit 03 Previous: Example for the design