本帖最后由 李挺 于 2013-2-1 09:38 编辑
- class Student
- {
- public void study()
- {
- System.out.println("study");
- }
- public void sleep()
- {
- System.out.println("tangzheshui");
- }
- }
- class AdvStudent extends Student
- {
- public void study()
- {
- System.out.println("adv study");
- }
- public void sleep()
- {
- System.out.println("zhanzheshui");
- }
- }
- class DoStudent
- {
- public static void dosome(Student stu)
- {
- stu.study();
- stu.sleep();
- }
- }
- class Demo2
- {
- public static void main(String[] args)
- {
- DoStudent.dosome(new AdvStudent());
- }
- }
复制代码 我定义对象new AdvStudent() 应该是父类型Student,
为什么打印的是子类型的
adv study
zhanzheshui
而不是父类型的
study
tangzheshui |