abstract class person
{
private String name;
private int age;
private String vacation;
{
System.out.println("它们都是黑马学员");
}
public person(){}
public person(String name,int age,String vacation)
{
this.name = name;
this.age = age;
this.vacation = vacation;
}
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;
}
public void setVacation(String vacation)
{
this.vacation = vacation;
}
public String getVacation()
{
return vacation;
}
public void show()
{
System.out.println("姓名:"+name+",年龄"+age+",假期"+vacation);
}
public abstract void study();
}
class student extends person
{
public student(){};
public student(String name,int age,String vacation)
{
super(name,age,vacation);
}
public void study()
{
System.out.println("学习javaSE");
}
}
class highstudent extends person
{
public highstudent(){};
public highstudent(String name,int age,String vacation)
{
super(name,age,vacation);
}
public void study()
{
System.out.println("学习javaEE");
}
}
class persontext
{
public static void main(String[] args)
{
/*
//利用父类无参
person p = new person();
p.setName("张曼玉") ;
p.setAge(21);
p.setVacation("我来3天例假了");
p.show();
//利用父类有参
person p1 = new person("林青霞",20,"来例假了");
p1.show();
*/
//利用子类无参1(student)
student s = new student();
s.setName("陈意涵") ;
s.setAge(25);
s.setVacation("5天假期");
s.show();
s.study();
//利用子类有参1(student)
student s1 = new student("张国荣",35,"3天休假");
s1.show();
s1.study();
//利用子类无参2(highstudent)
highstudent h = new highstudent();
h.setName("陈紫函") ;
h.setAge(27);
h.setVacation("7天假期");
h.show();
h.study();
//利用子类有参2(highstudent)
highstudent h1 = new highstudent("刘德华",45,"3天休假");
h1.show();
h1.study();
}
} |
|