/**
* mischen
* 2017年8月17日 上午7:45:04
*/
package com.mischen.cn;
/**
* @author mischen
* 2017年8月17日 上午7:45:04
*/
public class Person {
public void Person(){
System.out.println("Person A");
}
public Person(){
System.out.println("Person B");
}
int getAge(){
return 20;
}
public void printAge(){
System.out.println(getAge());
}
/**
* mischen
* 2017年8月17日 上午7:45:04
*/
public static void main(String[] args) {
Person p=new Student();
p.printAge();//Person B Student 25
}
}
class Student extends Person{
public Student(){
System.out.println("Student");
}
int getAge(){
return 25;
}
}
关于继承与重写的面试编程题
最新推荐文章于 2025-07-23 19:26:53 发布
本文通过一个具体的Java程序示例,介绍了如何在一个类(Person)中定义方法,并由其子类(Student)覆盖这些方法来展示不同的行为。该示例还演示了构造函数的调用过程及方法覆盖的应用。

7638

被折叠的 条评论
为什么被折叠?



