我的程序显示一个错误"无法解析符号'getThePixels'"(在类
以下是代码:
Main
中)。代码基本上创建了一个包含Resolution
类对象的Monitor
类。我正在尝试通过监视器对象访问Resolution
类方法。以下是代码:
Main:
public class Main {
Resolution resolution = new Resolution(10);
Monitor monitor = new Monitor(12,13,14,resolution);
monitor.getThePixels().pix();
}
监视器:
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;
}
}
解决方案:
public class Resolution {
private int pixels;
public Resolution(int pixels) {
this.pixels = pixels;
}
public void pix() {
System.out.println("resolution is" + pixels);
}
}