Mein Programm zeigt einen Fehler "kann das Symbol 'getThePixels' nicht auflösen (in Klasse Main
). Der Code erstellt im Grunde eine Monitor
Klasse, die ein Objekt der Klasse Resolution
enthält. Ich versuche, Resolution
Klassenmethode über Monitorobjekt zuzugreifen. Im Folgenden ist der Code:Warum funktioniert dieser Kompositionscode nicht?
Main:
public class Main {
Resolution resolution = new Resolution(10);
Monitor monitor = new Monitor(12,13,14,resolution);
monitor.getThePixels().pix();
}
Monitor:
public class Monitor {
private int height;
private int width;
private int length;
Resolution thePixels;
public Monitor(int height, int width, int length, Resolution thePixels) {
this.height = height;
this.width = width;
this.length = length;
this.thePixels = thePixels;
}
public int getHeight() {
return height;
}
public int getWidth() {
return width;
}
public int getLength() {
return length;
}
public Resolution getThePixels() {
return thePixels;
}
}
Auflösung:
public class Resolution {
private int pixels;
public Resolution(int pixels) {
this.pixels = pixels;
}
public void pix() {
System.out.println("resolution is" + pixels);
}
}
@JeroenHeier Es ist nicht Kumpel nicht kompiliert. Das ist was er gesagt hat. – CKing