"Hello, Amigo! Here I am. And I've brought you ... a big and interesting task about multiple inheritance."
3
Task
Java Core,
level 3,
lesson 6
Locked
Tom, Jerry and Spike
Use class and interfaces to implement the relationship between Tom, Jerry and Spike the Bulldog. The cat can move, eat, or be eaten. The mouse can move and be eaten. And the dog can move and eat (whoever it wants!).
It is SOOOOooooo overcomplicated ?
Sorry, I know I am complaining, and still a newbie in Java. But why not simplify it and use methods ?
eat(), move(), etc.
Finding this tricky also.. but I suspect because methods (eg. Run) are housed within classes (eg. Dog) and are accessible specifically by the object that's been created using that class (eg. Dog.run). Interfaces create a publicly available "method" (if its easier to refer to them that way) that allow classes of all kinds to use them ("inherit").
Eg. a Cat, a Dog, a Mouse can all access the same "Run" action because its programming sits outside the Cat/Dog/Mouse classes.
I think that's how it works. Could be wrong ha!
Alright, from the preceding topics what i conclude about:
Abstraction - is that it is used to create an idea of a system of classes, where we can make fundamental methods that the inheriting class can implement in its own way and we can also define implemented methods that are already common in all the derived classes
Interfaces - is much like abstraction but is used to define roles/methods that specific classes can implement in their own style and it is through these roles, using the mechanism of abstraction and polymorphism, we interact with objects of other classes.
GO TO FULL VERSION