已知一个类,创建一个类的对象 然后在创建另外一个类的对象,传入不同的参数,用java写代码,可以运行出来的。
2条回答 默认 最新
很大森 2021-06-30 11:34关注public class Student { private String name; private int age; private String hobby; public Student(String name, int age, String hobby) { this.name = name; this.age = age; this.hobby = hobby; } @Override public String toString() { return "Student [name=" + name + ", age=" + age + ", hobby=" + hobby + "]"; } public static void main(String[] args) { Student stu1 = new Student("张三",18,"看书"); Student stu2 = new Student("小西",18,"看剧"); System.out.println(stu1); System.out.println(stu2); } }本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报