Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Not only can you add new methods to effectively extend the definition of a class, but you can also add new instance variables. In both cases, the effect is cumulative. You can never subtract methods or instance variables through inheritance; you can only add—or, in the case of methods, add or override.
Let’s return to your simple ClassA and ClassB classes and make some changes. Add a new instance variable, y, to ClassB, like so: