- public class Animal {
- public void eat() {
- System.out.println("animal eatting...");
- }
- }
- class Bird extends Animal {
- public void eat() {
- System.out.println("bird eatting...");
- }
- public void fly() {
- System.out.println("bird flying...");
- }
- }
- class Demo {
- public static void main(String[] args) {
- Animal b = new Bird(); //此处将Bird的对象赋值给父类b的引用,是向上转型<b>(老师说我回答的这句话有错,向上转型不是这样的),求解....什么是向上转型? </b><span style="line-height: 30.7999992370605px;">父类引用 </span><b style="line-height: 30.7999992370605px;">到底是 </b><span style="line-height: 30.7999992370605px;">指用<b>父类</b>还是<b>子类....?</b></span>
-
- }
- }
复制代码
|
|