62,623
社区成员
发帖
与我相关
我的任务
分享
例:
class Employee
{
public void first()
{
System.out.println("Super.first");
}
public void second()
{
System.out.println("Super.second");
}
}
class Manager extends Employee
{
public void first()
{
System.out.println("Child.first");
}
public void third()
{
System.out.println("Child.third");
}
}
public class Test
{
public static void main(String[] args)
{
Employee parent = new Manager();
parent.first();
parent.second();
parent.third();//error
}
}
public class Tester : Employee {
public void first() {
System.out.println("Tester.first()");
}
}
public class Test2 {
public static void callFirst(Employee e) {
e.first();
}
public static void main(String[] args) {
Employee joe = new Manager();
callFirst(joe);
Employee michael = new Tester();
callFirst(michale);
}
}