Author
Multiple interface inheritance problem.
Varun Narang
Ranch Hand
Joined: Nov 19, 2004
Posts: 30
Hi all,
I was trying and not able to understand the behaviour of code that'd satisfy the multiple inheritance for following case;
If any once can please explain the behaviour and implementation in respective cases, it'd be a great help.
Thanks & Regards,
+ Varun
Your computer system is like AC, it's of no use when you open Windows ;)
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12617
posted Jun 20, 2010 06:35:19
0
As far as I know you wouldn't be able to do this.
First, consider greet() . Even ignoring inheritance, you're not allowed to have two methods that differ only by their return type.
Check out this section in the JLS .
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
Ignoring the greet() method problems, there is only one way to be able to satisfy the contract for both Hello1.sayHello() and Hello2.sayHello() - by throwing no exceptions at all. After all, if it throws MyException it violates the contract for Hello2.sayHello(), and if it throws MyException2 it violates the contract for Hello1.sayHello().
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Varun Narang
Ranch Hand
Joined: Nov 19, 2004
Posts: 30
@David, Thanks for the advice, I'll keep that in mind.
@Rob, I was thinking in the similar direction, Thanks for confirming. This is more of a 'obey the contract' problem than a programming puzzle.
Thanks once again.
Regards,
Varun.
Jim Hoglund
Ranch Hand
Joined: Jan 09, 2008
Posts: 525
Yes, an attempt to implement the interfaces show both incompatible
return type and incompatible exception type errors.
Jim ... ...
BEE MBA PMP SCJP-6
subject: Multiple interface inheritance problem.