• Post Reply Bookmark Topic Watch Topic
  • New Topic

overriding doubt  RSS feed

 
akila sekaran
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


can we call animal's eat() from within one of mammal's methods?
 
Michael Krimgen
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bird extends Animal, yes.
Mammal extends Bird?
 
akila sekaran
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Bird extends Animal, yes.
Mammal extends Bird?



Bat is a mammal
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
akila sekaran wrote:Bat is a mammal

So in your system, Bats are Birds then?

Winston
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course they are. And whales are a kind of fish.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!