已知一个类,创建一个类的对象 然后在创建另外一个类的对象,传入不同的参数,用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); } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥100 set_link_state
- ¥15 虚幻5 UE美术毛发渲染
- ¥15 CVRP 图论 物流运输优化
- ¥15 Tableau online 嵌入ppt失败
- ¥100 支付宝网页转账系统不识别账号
- ¥15 基于单片机的靶位控制系统
- ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
- ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
- ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
- ¥15 手机接入宽带网线,如何释放宽带全部速度