OO Programming with Java


Inheritance

  1. How to display and compare groups ?
    In particular, all Java classes inherit from Object class that offers basic capabilities to transform objects into String (to print them) or to compare objects (theor memory adress).
System.out.println( g3.toString() ); // RestrictedGroup@1be6f5c3
System.out.println( g3.equals(g3) ); // true

As a remark, the println method is 'polymorphic' and accepts various types of parameter: String, int or Object. In this last case, the println operation call the toString() operation on the object to transform it into string before printing.
So, the previous expression can be simplified to:

System.out.println( g3 );

As a complement, all the primitive datatypes are associted to a "Wrapper" classes that proposes in particular operations to (de)serialize values; see for instance the Integer class.


UML/SysML class diagram


5 - 14