OO Programming with Java


Inheritance

  1. Inheritance is at the origin of the polymorphism concept that says that
A class can be sustituted by any of its subclass (polymorphism)

For instance:

Group           g3 = new RestrictedGroup("Guitar",5);
  1. Most of the classes from Java API belong to an inheritance hierarchy. As an illustration, a (partial) hierarchy of the InputStreams, whose an instance is System.in previously mentionned, is
+ InputStream
    + FileInputStream
    + ByteArrayInputStream
    + ObjectInputStream
    + FilterInputStream

And an application of the polymorphism is:

java.util.Scanner scan;
scan = new Scanner(System.in);                          // read from command line
scan = new Scanner(new FileInputStream("groups.txt") ); // read from file
Group ng = new Group( scan.nextLine() );

Nb. Scanner is detailled here.


UML/SysML class diagram


4 - 14