CATEGORII DOCUMENTE |
Asp | Autocad | C | Dot net | Excel | Fox pro | Html | Java |
Linux | Mathcad | Photoshop | Php | Sql | Visual studio | Windows | Xml |
It is very common to use composition and inheritance together. The following example shows the creation of a more complex class, using both inheritance and composition, along with the necessary constructor initialization:
//: PlaceSetting.java
// Combining composition & inheritance
class Plate
class DinnerPlate extends Plate
class Utensil
class Spoon extends Utensil
class Fork extends Utensil
class Knife extends Utensil
// A cultural way of doing something:
class Custom
public class PlaceSetting extends Custom
public static void main(String[] args)
While the compiler forces you to initialize the base classes, and requires that you do it right at the beginning of the constructor, it doesn't watch over you to make sure that you initialize the member objects, so you must remember to pay attention to that.
Politica de confidentialitate | Termeni si conditii de utilizare |
Vizualizari: 626
Importanta:
Termeni si conditii de utilizare | Contact
© SCRIGROUP 2024 . All rights reserved