Java Inheritance example - group of classes - step by step
Archive - Originally posted on "The Horse's Mouth" - 2015-02-08 09:44:10 - Graham EllisTwo examples from last week's Java course ...
a) [here] - an example of a base class, two classes that inherit from it, and a test class.
b) [here] - that same example extende to add
• an array of objects of various associated types (so polymophism in action)
• an abtract class, meaning that I can use that polymorphism and have an array of objects that implement the base class
• calls to super allowing my subclass constructors bo be based on operations in my base class constuctor ("a train is a piece of transport with ...")
• overloading of methods where one particular subclass behaves differently
It's all too easy to write examples during a course, illustrating the easy starting point ... but then get carried away with the result that the final examples as published on the web or in a bok or in notes no longer show people the steps to deriving the code - hence my two examples here.
Posting this on a Sunday ... heading off in an hour for the next on site Java course!