3个回答
2014-06-13 · 知道合伙人数码行家
关注
展开全部
class User{
String name;
String sex;
int age;
public User(String name, String sex, int age){
this.name = name;
this.sex = sex;
this.age = age;
}
}
public class Demo{
public static void main(String[] args){
User u = new User("张三","男",20);
System.out.println("姓名:"+name+"\n性别:"+sex+"\n年龄:"+age);
}
}
追问
谢谢了
追答
不客气
2014-06-13 · 知道合伙人软件行家
关注
展开全部
public class User {
private String name;
private char sex;
private int age;
public User() {
}
public User(String name, char sex, int age) {
this.name = name;
this.sex = sex;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String toString() {
return "User [name=" + name + ", sex=" + sex + ", age=" + age + "]";
}
}
private String name;
private char sex;
private int age;
public User() {
}
public User(String name, char sex, int age) {
this.name = name;
this.sex = sex;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String toString() {
return "User [name=" + name + ", sex=" + sex + ", age=" + age + "]";
}
}
追问
谢谢了
追答
不知道楼主是用到web上,还是桌面应用上,写的简单,求采纳,嘿嘿···
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
三个private属性
利用get set 获取与设置属性
public class User {
private String name;
private String sex;
private int age;
/**
* @param name
* @param sex
* @param age
*/
public User(String name, String sex, int age) {
super();
this.name = name;
this.sex = sex;
this.age = age;
}
/**
*
*/
public User() {
super();
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the sex
*/
public String getSex() {
return sex;
}
/**
* @param sex the sex to set
*/
public void setSex(String sex) {
this.sex = sex;
}
/**
* @return the age
*/
public int getAge() {
return age;
}
/**
* @param age the age to set
*/
public void setAge(int age) {
this.age = age;
}
}
利用get set 获取与设置属性
public class User {
private String name;
private String sex;
private int age;
/**
* @param name
* @param sex
* @param age
*/
public User(String name, String sex, int age) {
super();
this.name = name;
this.sex = sex;
this.age = age;
}
/**
*
*/
public User() {
super();
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the sex
*/
public String getSex() {
return sex;
}
/**
* @param sex the sex to set
*/
public void setSex(String sex) {
this.sex = sex;
}
/**
* @return the age
*/
public int getAge() {
return age;
}
/**
* @param age the age to set
*/
public void setAge(int age) {
this.age = age;
}
}
追问
谢谢了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |