permaculture playing cards*
The moose likes Java in General and the fly likes Question on Multiple inheritance using interfaces. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Question on Multiple inheritance using interfaces." Watch "Question on Multiple inheritance using interfaces." New topic
Author

Question on Multiple inheritance using interfaces.

Tushar Ravi
Greenhorn

Joined: Nov 23, 2010
Posts: 8
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

Joined: Oct 02, 2003
Posts: 11154
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Tushar Ravi
Greenhorn

Joined: Nov 23, 2010
Posts: 8
Awesome reply fred . I liked the way you explained with the example "Go clean your room" .

Thanks a lot.

Tushar
Vinod Vinu
Ranch Hand

Joined: Aug 30, 2009
Posts: 217
same here, awesome e.g. fred
appreciated !!!


Vinod Kumar Nair
"Any fool can write code that a computer can understan. Good programmers write code that humans can understand."
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on Multiple inheritance using interfaces.
 
Similar Threads
difference bet. abstract class and interface
multi-inheritance
Invalid SQL from
Newbie: Returning objects via JAX-RPC?
Uncertain about Set.contains()