next up previous
Next: Inheritance: example Up: Unit 08 Previous: Summary

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 add new functionalities and/or new information.

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

For example, suppose we have defined a class Person:

public class Person {
  ...
}

We can derive the class Student from Person:

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 08 Previous: Summary