当尝试完成一个任务时(“创建一个包含两个String类型字段的Dog类:name和says。在方法中 main() 创建两个具有不同名称(spot 和 scruffy)和消息的 Dog 对象。 打印每个对象的两个字段的值”)项目无法启动。 程序本身:
public class Doges {
String name;
String says;
public Doges(String name, String says) {
this.name = name;
this.says = says;
}
public static void main (String[] args) {
Doges spot = new Doges ( "Spot","My name Spot bro, u know?");
Doges scruffy = new Doges ("Scruffy","Yeah, i know man, but im - Scruffy and im Dog");
System.out.println(STR."\{spot.name}: \{spot.says}");
System.out.println(STR."\{scruffy.name}: \{scruffy.says}");
}
}
我尝试交换课程,但这不是问题的原因。
为什么不做下面的事情
public class Doges {
String name;
String says;
public Doges(String name, String says) {
this.name = name;
this.says = says;
}
public static void main (String[] args) {
Doges spot = new Doges ( "Spot","My name Spot bro, u know?");
Doges scruffy = new Doges ("Scruffy","Yeah, i know man, but im - Scruffy and im Dog");
System.out.println(spot.name+" : "+spot.says);
System.out.println(scruffy.name+" : "+scruffy.says);
}
}