pri*_*am 3 java methods compiler-errors
我的程序显示错误"无法解析符号'getThePixels'"(在课堂上Main).代码基本上创建了一个Monitor包含Resolution类对象的类.我试图Resolution通过监视器对象访问类方法.以下是代码:
主要:
public class Main {
Resolution resolution = new Resolution(10);
Monitor monitor = new Monitor(12,13,14,resolution);
monitor.getThePixels().pix();
}
Run Code Online (Sandbox Code Playgroud)
监控:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
解析度:
public class Resolution {
private int pixels;
public Resolution(int pixels) {
this.pixels = pixels;
}
public void pix() {
System.out.println("resolution is" + pixels);
}
}
Run Code Online (Sandbox Code Playgroud)
小智 5
你应该写那样的Main类.
public class Main {
public static void main(String[] args) {
Resolution resolution = new Resolution(10);
Monitor monitor = new Monitor(12,13,14,resolution);
monitor.getThePixels().pix();
}
}
Run Code Online (Sandbox Code Playgroud)
你不能在类体内的对象上调用方法.
| 归档时间: |
|
| 查看次数: |
78 次 |
| 最近记录: |