haslflafjl 2022-03-03 10:00 采纳率: 80%
浏览 65
已结题

JAVA代码运行逻辑解读

public class main {

    public static void main(String[] args) {
        Human human1=new Human("Rick",24,90);
        Human human2=new Human("Jim", 12,90);
        System.out.println(human1.name);
        human1.eat();
        human2.drink();
    }

}

public class Human {
    String name;
    int age;
    double weight;
    Human(String name,int age,double weight){
        this.name=name;
        this.age=age;
        this.weight=weight;
    }
    void drink() {
        System.out.println(this.name+" is drinking.");
    }
    void eat() {
        System.out.println(this.name+" is eating.");
    }
    
}

运行结果:
Rick
Rick is eating.
Jim is drinking.

  • 写回答

4条回答 默认 最新

  • 谛凌 2022-03-03 10:12
    关注

    img

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 3月11日
  • 已采纳回答 3月3日
  • 创建了问题 3月3日