Phase 1 Language Basics + Advanced _1-3-Java language senior _02- inheritance and polymorphism _ _16_ Section 7 of the inner class as a member variable type interfaces


Any type of data can be used as a member variable of type,
the interface can also be used as a member variable of the type of

new Hero class

interfaces Skill defined skills. Then use a method which defines the




generated code


after the definition of a hero class, set over the name, also set skills. But this skill is an interface

There are several ways to create an implementation class here, which way to override the

set of skills, new skills to achieve class

hero class method of increasing attacks


calling the attack method



modified cast

In the form of an anonymous inner class




At the same time the use of anonymous inner classes and anonymous objects








 

Guess you like

Origin www.cnblogs.com/wangjunwei/p/11223443.html