拜托各位大神

欧皇是我的目标 2019-04-12 10:51:32
设计一个类Doctor:该Doctor类有一个String类型的属性“name”。创建一个测试类TestDoctor,使用Doctor创建两个对象:你的姓名(例如:zhangsan)和liSi,它们的name属性分别是:“张三”和“李四”,并输出name的值。注意:1创建两个类,2要用到构造函数。
...全文
59 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
棒极了
咦哟~~~ 2019-04-12
  • 打赏
  • 举报
回复
public class Doctor { String name;//name属性 public Doctor(String name) { //有参的构造函数 this.name = name; } } class TextDoctor{ public static void main(String[] args) { Doctor doctor1 = new Doctor("张三"); Doctor doctor2 = new Doctor("李四"); System.out.println(doctor1.name+doctor2.name); } }
931828653 2019-04-12
  • 打赏
  • 举报
回复
public class Doctor { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } public Doctor(String name) { this.name = name; } public Doctor() { } @Override public String toString() { return "Doctor{" + "name='" + name + '\'' + '}'; } } class TestDoctor{ public static void main(String[] args){ String name_one = "张三"; Doctor doctor_one = new Doctor(name_one); String name_two = "李四"; Doctor doctor_two= new Doctor(name_two); System.out.println(doctor_one); System.out.println(doctor_two); } } 输出结果: Doctor{name='张三'} Doctor{name='李四'}

51,411

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧