[Java] 類別 物件建立 資料成員賦值與存取


class Dog{
String name = new String();
String says = new String();
}

public class Exercise_3_5 {

public static void main(String[] args) {

Dog dog1 = new Dog();
dog1.name = "Spot";
dog1.says = "Ruff!";

Dog dog2 = new Dog();
dog2.name = "Scruffy";
dog2.says = "Wurf!";

println(dog1.name + " says " + dog1.says);
println(dog2.name + " says " + dog2.says);

}

public static void print(String str) {
System.out.print(str);
}

public static void println(String str) {
System.out.println(str);
}
}

有疑問? 留個言吧!

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料