class ExtendsDemo
{
public static void main(String[] args)
{
//System.out.println("Hello World!");
Student s=new Student();
//s.setName("zhangsan");
//System.out.println(s.getName());
s.speak();
//Person p=new Person("wanger",20);
}
}
class Person
{
int age;
String name;
void speak()
{
System.out.println("Hello World!");
}
public void setAge(int age)
{
if(age>0&&age<130)
{
this.age=age;
}
}
public int getAge()
{
return age;
}
public void setName(String name)
{
this.name=name;
}
public String getName()
{
return name;
}
/*Person(String name,int age)
{
this.name=name;
this.age=age;
System.out.println("name="+name+" age"+age);
}*/
}
class Student extends Person
{
void show()
{
System.out.println("student study");
}
}
class Work extends Person
{
void show()
{
System.out.println("work ");
}
}
这是我写的person类,应该与学生类 差不多,仅供参考 |