gpt4 book ai didi

java - 在类 exo1.Batiment 中找不到 Main 方法,请将 main 方法定义为 :public static void main(String[] args) or a JavaFX application class

转载 作者:行者123 更新时间:2023-12-01 18:36:46 24 4
gpt4 key购买 nike

大家好,我在运行 java 程序时遇到问题(我是 java 新手):当我在 Eclipse 上运行代码时,它向我显示上面关于未找到 main 的错误,但我的程序中有一个 main 并声明为静态,这是我的代码(法语名称 ar 很抱歉):

package exo1;

public class Batiment {

String adresse ;
int surfaceHabitable ;

public Batiment(String adresse , double surface) {
this.adresse = adresse ;
this.surfaceHabitable = (int) surface ;
}

public String toString() {
return "-- L'adresse est : " + adresse + "\n" + "-- La surface habitable est : " + surfaceHabitable + " metre carres\n" ;
}


class Maison extends Batiment {
int nbPieces;
int surfaceJardin;

public Maison(String adresse, int surfaceH, int surfaceJ, int nbPieces) {
super(adresse, surfaceH);
this.nbPieces = nbPieces;
this.surfaceJardin = surfaceJ;
}

public String toString() {
return super.toString() + "-- La surface du jardin est : " + surfaceJardin + " metre carres" + "\n-- Le nombre de pieces est : " + nbPieces ;
}
}
class Immeuble extends Batiment{
int nbAppart ;

public Immeuble(String adresse, int surface, int numAppart) {
super(adresse, surface);
this.nbAppart = numAppart ;
}

public String toString() {
return super.toString() + "-- Le numero d'apparetement est : " + nbAppart ;
}
}

public static class TestBatiment{
public static void main(String[] args){
Batiment B1 = new Batiment("app 5 imm riad res rabat CYM", 100);
Maison M1 = B1.new Maison("app 5 imm riad res rabat CYM", 90, 50, 5);
Immeuble I1 = B1.new Immeuble("app 5 imm riad res rabat CYM", 100, 5);
System.out.println(B1);
System.out.println(M1);
System.out.println(I1);
}
}


}

最佳答案

您放入单个文件中的代码确实可以正确编译,因此我认为您没有尝试运行良好的 java 文件(即 TestBatiment 文件)

关于java - 在类 exo1.Batiment 中找不到 Main 方法,请将 main 方法定义为 :public static void main(String[] args) or a JavaFX application class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60022091/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com