所以這種情況是有點令人沮喪的我,因爲我的在線老師喜歡我們只是通過自己獨立學習在線課程和我到處都看上去還是我找不到如何使用無參數完全無參數的構造
以下是我正在創建的程序,但是因爲我知道它不能在沒有main的情況下運行它,但是每當我輸入main時它都不會運行no-args構造,並且我通常不知道我在哪裏搞亂。
import java.util.Scanner;
public class Week07_Assignment {
Scanner input = new Scanner(System.in);
private double height = 1;
private double width=1;
private double h;
private double w;
public void createrectangle(){
System.out.println("Give me both the height and width of this rectangle");
height = heightgetter(height);
width = heightgetter(width);
area(height, width);
perimeter(height, width);
}
public double heightgetter(double a){
a = input.nextDouble();
return a;
}
public double widthgetter(double a){
a = input.nextDouble();
return a;
}
public void area(double a, double b){
double area = a * b;
System.out.println("This is the area: " +area);
}
public void perimeter(double a, double b){
double perimeter = 2 * (a + b);
System.out.println("This is the area: " +perimeter);
}
}
'main'方法是一個靜態方法,沒有構造函數被調用。如果你需要調用默認的構造函數,你必須明確地做。如果你的教授拒絕解釋他的學生不理解的東西,那麼......不是一個好的IMO教授。 – BackSlash
如果你想運行「Week07_Assignment」的構造函數,那麼你必須創建它的對象。 –