练习5:创建一个class类,包含连两个String字段 :name、says。在main方法中创建两个Dog方法 一个命名为spot 叫声为 Ruff,另一个命民为scruffy,叫声为:Wuff;然后显示 他们的名字和叫声。
public class quan {
String name;
String says; public void setName(String name){
this.name =name;
} public String getName() {
return name;
} public String getSays() {
return says;
} public void setSays(String says) {
this.says = says;
}
}
public class Dog { public static void main(String[] args) {
quan spot = new quan();
quan scruffy = new quan();
quan xiaoQ = new quan(); spot.setName("spot");
scruffy.setName("scruffy");
xiaoQ.setName("xiaoQ");
spot.setSays("Ruff!"); System.out.println(spot.getName());
System.out.println(spot.getSays());
System.out.println(scruffy.getName());
System.out.println(scruffy.getSays()); }
}
2020-04-30