Person.java
public class Person
{
int age;
String name;
String school;
Person(String name,int age)
{
this.name=name;
this.age=age;
}
Person(String string, int age, String school)
{
this.name=name;
this.age=age;
this.school=school;
}
void sayHello(Student s)
{
System.out.println("My school is "+school);
}
void sayHello()
{
System.out.println("wpx");
}
}
Student.java
public class Student extends Person
{
String school;
int score;
void sayHello(Student another)
{
System.out.println("Hi!");
if(school==another.school )
System.out.println(" Shoolmates");
}
boolean isGoodStudent()
{
return score>=90;
}
void testThisSuper()
{
int a;
a=age;
a=this.age;
a=super.age;
}
void sayHello()
{
super.sayHello();
System.out.println("My school is "+school);
}
Student(String name,int age,String school)
{
super(name,age);
this.school=school;
}
// Student()();
public static void main(String []args)
{
Person p=new Person("Liming",50);
Student s=new Student("Wangqiang",20,"PKU");
Person p2=new Student("Zhangyi",18,"THU");
// Student s2=(Student)p2;//强制转换
// Student s3=(Student)p;
p.sayHello(s);
Person []manypeople = new Person[100];
manypeople[0] = new Person("Li",18);
manypeople[1] = new Person("Wang",18,"PKU");
}
}