class Student(){
String name;
int age;
public void method(){
this.name = name;
this.age = age;
}
setName(){
String name = "张三";
int age = 20;
}
getName(String name , int age){
return ;
}
}
class Demo{
public static void main(String[] args){
Student p = new Student();
p.method;
}
}作者: _王涛 时间: 2013-3-30 23:15
正确答案因该是:
class Student{
private String name;
private int age;
public Student() {//无参构造方法
}
public Student(String name, int age) {//有参构造方法
this.name = name;
this.age = age;
}
public String getName() {//得到名字的值
return name;
}
public void setName(String name) {//设置名字
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
class Test
{
public static void main(String[] args)
{
Student st=new Student("king",24);//为其进行初始化赋值
System.out.println(st.getName());//得到返回的年龄
System.out.println(st.getAge());