Chark-程序员BOLG

Chark BOLG

java运行时多态,后期绑定的初始化顺序

结果:

Creating Characteristic has tail
Creating Description small mammal
Rodent()
Creating Characteristic larger
Creating Description black
Rat()
Rat
===============================
Creating Characteristic has tail
Creating Description small mammal
Rodent()
Creating Characteristic likes cheese
Creating Description nocturnal
Mouse()
Mouse
===============================
Creating Characteristic has tail
Creating Description small mammal
Rodent()
Creating Characteristic climbs trees
Creating Description likes nuts
Squirrel()
Squirrel
===============================
Creating Characteristic has tail
Creating Description small mammal
Rodent()
Creating Characteristic climbs trees
Creating Description likes nuts
Squirrel()
Squirrel
===============================
Creating Characteristic has tail
Creating Description small mammal
Rodent()
Creating Characteristic likes cheese
Creating Description nocturnal
Mouse()
Mouse
===============================
Creating Characteristic has tail
Creating Description small mammal
Rodent()
Creating Characteristic larger
Creating Description black
Rat()
Rat
===============================
Creating Characteristic has tail
Creating Description small mammal
Rodent()
Creating Characteristic climbs trees
Creating Description likes nuts
Squirrel()
Squirrel
===============================
Creating Characteristic has tail
Creating Description small mammal
Rodent()
Creating Characteristic climbs trees
Creating Description likes nuts
Squirrel()
Squirrel
===============================
Creating Characteristic has tail
Creating Description small mammal
Rodent()
Creating Characteristic larger
Creating Description black
Rat()
Rat
===============================
Creating Characteristic has tail
Creating Description small mammal
Rodent()
Creating Characteristic likes cheese
Creating Description nocturnal
Mouse()
Mouse
===============================

 

说明,上塑造型时,发生了运行时多态的时候,首先初始化基类,然后再初始化子类,然后再后期绑定子类的方法。

阅读更多
文章标签: java string class c
个人分类: java
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭