Forums Register Login

overriding doubt

+Pie Number of slices to send: Send


can we call animal's eat() from within one of mammal's methods?
+Pie Number of slices to send: Send
Hi Akila,

That depends on what is in the (...).

If eat() has the same signature, thus the same list of parameters, the eat-method in mammal overrides the eat-method from animal.

As Bird does not override the eat-method, you still can call the animal's eat method by



Like that, you call bird's eat-method which is the one it inherits from animal.

However, bird also overrides animal's eat-method, there is no way to call animal's eat-method from mammal as super.super.eat() does not work.
1
+Pie Number of slices to send: Send
Bird extends Animal, yes.
Mammal extends Bird?
+Pie Number of slices to send: Send
 

Campbell Ritchie wrote:Bird extends Animal, yes.
Mammal extends Bird?




Bat is a mammal
+Pie Number of slices to send: Send
 

akila sekaran wrote:Bat is a mammal


So in your system, Bats are Birds then?

Winston
+Pie Number of slices to send: Send
Of course they are. And whales are a kind of fish.
Just the other day, I was thinking ... about this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 582 times.
Similar Threads
recursive constructor invocation
Overriden and Overriding Methods Declaration Conundrum.
Inheritence and Typecasting in java
classpath problem
Basic question about Overload/Override
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 09:05:04.