• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on Multiple inheritance using interfaces.

 
Tushar Ravi
Greenhorn
Posts: 10
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I have question on this topic.

I have an interface ViewActions.java


another interface DataActions.java



I am implementing the above interfaces in a class Test.java



This compiles and runs fine.

I want to know how will this work ? How will the JVM know if the testData() overridden is from DataActions.java or ViewActions.java.

Many thanks in advance.

Tushar
 
fred rosenberger
lowercase baba
Bartender
Posts: 12187
34
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your mom said "Go clean your room" and your dad said "go clean your room", do you have to clean your room twice? If you only clean your room once, how does someone know if you did it for your mom or for your dad?

The truth is - it doesn't matter, because doing it once satisfies both parent's requirements - and it's the same here in java and interfaces..

when you say

You're simply saying "I promise that the code I write below will satisfy the requirements of both ViewActions and DataActions." As soon as you write the "public int testData()" method, you have satisfied that part of the requirements for each interface (there could be others, although there is not in your example).

now, IF the two methods with the same name need to to fundamentally different things, you have a design issue.
 
Tushar Ravi
Greenhorn
Posts: 10
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Awesome reply fred . I liked the way you explained with the example "Go clean your room" .

Thanks a lot.

Tushar
 
Vinod Vinu
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
same here, awesome e.g. fred
appreciated !!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic