g9:uebungen:konstruktoren:start
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
g9:uebungen:konstruktoren:start [2021/01/20 17:44] – angelegt Martin Pabst | g9:uebungen:konstruktoren:start [2022/06/30 07:43] (aktuell) – [Das Schlüsselwort "this"] Martin Pabst | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
====== Konstruktoren ====== | ====== Konstruktoren ====== | ||
- | |||
- | {{youtube> | ||
- | |||
Wir haben inzwischen schon viele Objekte instanziert, | Wir haben inzwischen schon viele Objekte instanziert, | ||
< | < | ||
Zeile 67: | Zeile 64: | ||
<script type=" | <script type=" | ||
- | Buntstift rotstift = new Buntstift(Color.red); | + | Buntstift rotstift = new Buntstift(0xff0000); |
rotstift.schreibe(" | rotstift.schreibe(" | ||
- | Buntstift grünstift = new Buntstift(Color.lime); | + | Buntstift grünstift = new Buntstift(0x00ff00); |
grünstift.schreibe(" | grünstift.schreibe(" | ||
rotstift.schreibe(" | rotstift.schreibe(" | ||
Zeile 76: | Zeile 73: | ||
class Buntstift { | class Buntstift { | ||
- | Color farbe; | + | int farbe; |
// Das ist die Konstruktor-Methode ("der Konstruktor" | // Das ist die Konstruktor-Methode ("der Konstruktor" | ||
// dass sie den Bezeichner der Klasse (" | // dass sie den Bezeichner der Klasse (" | ||
- | | + | |
farbe = farbe1; | farbe = farbe1; | ||
} | } | ||
Zeile 121: | Zeile 118: | ||
<div class=" | <div class=" | ||
<script type=" | <script type=" | ||
- | Buntstift rotstift = new Buntstift(Color.red); | + | Buntstift rotstift = new Buntstift(0xff0000); |
rotstift.schreibe(" | rotstift.schreibe(" | ||
class Buntstift { | class Buntstift { | ||
- | Color farbe; | + | int farbe; |
- | | + | |
farbe = farbe; | farbe = farbe; | ||
} | } | ||
Zeile 150: | Zeile 147: | ||
farbe = farbe; | farbe = farbe; | ||
</ | </ | ||
- | in Zeile 9, dass der Wert des Parameters '' | + | in Zeile 9, dass der Wert des Parameters '' |
Wir müssen dem Compiler irgendwie mitteilen, dass der Bezeichner '' | Wir müssen dem Compiler irgendwie mitteilen, dass der Bezeichner '' | ||
<code learnj> | <code learnj> | ||
Zeile 159: | Zeile 156: | ||
<div class=" | <div class=" | ||
<script type=" | <script type=" | ||
- | Buntstift rotstift = new Buntstift(Color.red); | + | Buntstift rotstift = new Buntstift(0xff0000); |
rotstift.schreibe(" | rotstift.schreibe(" | ||
class Buntstift { | class Buntstift { | ||
- | Color farbe; | + | int farbe; |
- | | + | |
this.farbe = farbe; | this.farbe = farbe; | ||
} | } |
g9/uebungen/konstruktoren/start.1611161096.txt.gz · Zuletzt geändert: 2021/12/29 11:29 (Externe Bearbeitung)