Bild ist gemeinfrei
?
?
?
?
?
public class Circle {
private float x;
private float y;
private float radius;
public Circle(float xc, float yc, float r) {
this.x = xc;
this.y = yc;
this.radius = r;
}
}Wie viel Speicher
braucht ein
Circle-Objekt?
live
Wo?
Wofür?
Wer?
class Shape {
protected float x;
protected float y;
Shape(float xc, float yc) {
this.x = xc;
this.y = yc;
}
}class Circle extends Shape {
private float radius;
Circle(float xc, float yc, float r) {
super(xc, yc);
this.radius = r;
}
}
Primitive Datentypen (int, char, …) brauchen Speicher ➔ auf dem Stack
Objekte brauchen auch Speicher
➔ auf dem Heap
Referenzen selbst brauchen keinen Speicher
➔ nur die Objekte, auf die sie zeigen
Keine Referenz zeigt mehr auf ein Objekt:
➔ Objekt wird vom Garbage Collector entsorgt