java初入学门求带,跑出下面内容,怎么输出

m0_37613072 2017-09-05 01:34:56
public class StringMothe {

/**
* @param args
*/

private String name;
private static String boy;
private String girl;
private int age ;
private float height;
private float weight;

public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setBoy(String boy) {
this.boy = boy;
}
public String getBoy() {
return boy;
}

public void setGirl(String girl) {
this.girl = girl;
}

public String getGirl() {
return girl;
}

public void setAge(int age) {
this.age = age;
}

public int getAge() {
return age;
}

public void setHeight(float height) {
this.height = height;
}

public float getHeight() {
return height;
}

public void setWeight(float weight) {
this.weight = weight;
}

public float getWeight() {
return weight;
}

public StringMothe() {
// TODO Auto-generated constructor stub
}

public static void main(String[] args) {
// TODO Auto-generated method stub
StringMothe str=new StringMothe();
str.setName("张三");
str.setBoy(boy);
str.setAge(12);
str.setHeight(170);
str.setWeight(60);
System.out.println(str);

}

}
...全文
187 6 打赏 收藏 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
「已注销」 2017-09-05
  • 打赏
  • 举报
回复
引用 4 楼 m0_37613072 的回复:
[quote=引用 3 楼 ilovelizehui 的回复:] 使用str的get开头的方法。 如 System.out.println(str.getName());
ok,能解释一下分装类有什么用吗?举例说明一下。[/quote] 封装类通常是将变量私有化,你只能通过类提供的public方法访问它,而不能随意地直接通过属性修改。 在public方法中可以限制审核
蓝以雪 2017-09-05
  • 打赏
  • 举报
回复
重写tostring
m0_37613072 2017-09-05
  • 打赏
  • 举报
回复
引用 3 楼 ilovelizehui 的回复:
使用str的get开头的方法。 如 System.out.println(str.getName());
ok,能解释一下分装类有什么用吗?举例说明一下。
「已注销」 2017-09-05
  • 打赏
  • 举报
回复
使用str的get开头的方法。 如 System.out.println(str.getName());
m0_37613072 2017-09-05
  • 打赏
  • 举报
回复
引用 1 楼 pany1209 的回复:
快捷键重新toString方法。。。。。
tostring 是什么?能详细点吗?
李德胜1995 2017-09-05
  • 打赏
  • 举报
回复
快捷键重新toString方法。。。。。

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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