/*
案例:定义学生类。
*/
class Student
{ String name;
int age;
static String country;
//无参构造
public Student(){
System.out.println("无参构造方法");
}
//有参构造
public Student(String name,int age){
this.name=name;
this.age=age;
this.country=country;
}
public Student(String name,int age,String country){
this.name=name;
this.age=age;
this.country=country;
}
public void show(){
System.out.println(name+"****"+age+"****"+country);
}
public void setName(String name){
this.name=name;
}
public String getName(){
return name;
}
public void setAge(int age){
this.age=age;
}
public int getAge(){
return age;
}
}
class StaticTest
{
public static void main(String[] args)
{
//创建对象
Student s1=new Student("林青霞",26);
s1.show();
Student s2=new Student("郝永亮",27,"中国");
s1.show();
}
}
输出的结果是过少?
|
|