JAVA面向對象練習

package demo;

public class Demo5 {
    //構造器
    Demo5(String name,int age, String color,String action){
        this.name = name;
        this.age = age;
        this.color = color;
        this.action = action;
    }
    //成員變量
    String name;
    int age;
    String color;
    String action;

    //方法
    String fa() {
        return  this.color + "的" + this.name + "正在" + this.action;
    }

    void go() {
        System.out.println(this.name + "正在奔跑");
    }


    public static void main(String[] args) {

        Demo5 dog = new Demo5("dog",5,"黑色","奔跑");

        System.out.println(dog.age);
        System.out.println(dog.fa());
        dog.go();
    }




}
發佈了33 篇原創文章 · 獲贊 5 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章