3个回答
展开全部
class Student {
private String name;
private int age;
public Student(String name, int age){
this.setName(name);
this.setAge(age);
}
public void setName(String name){
this.name=name;
}
public void setAge(int age){
this.age=age;
}
public String getName(){
return this.name;
}
public int getAge(){
return this.age;
}
public String toString(){
return "姓名-->"+this.getName()+"\t"+
"年龄-->"+this.getAge();
}
}
public class StudentDemo{
public static void main(String args[]){
Student stu=new Student("张三",20);
System.out.println(stu);
}
}
楼主,给分啊~~~~~~~~~~
private String name;
private int age;
public Student(String name, int age){
this.setName(name);
this.setAge(age);
}
public void setName(String name){
this.name=name;
}
public void setAge(int age){
this.age=age;
}
public String getName(){
return this.name;
}
public int getAge(){
return this.age;
}
public String toString(){
return "姓名-->"+this.getName()+"\t"+
"年龄-->"+this.getAge();
}
}
public class StudentDemo{
public static void main(String args[]){
Student stu=new Student("张三",20);
System.out.println(stu);
}
}
楼主,给分啊~~~~~~~~~~
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询