File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Curious case about inheritance & Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Curious case about inheritance & Interface" Watch "Curious case about inheritance & Interface" New topic

Curious case about inheritance & Interface

Jose Campana
Ranch Hand

Joined: May 28, 2007
Posts: 339
Bon jour, coding associates!

Not a minute ago was a friend of mine here, and I was trying to explain to him some basics about Java, because he desires to do well in a test he has to take as part of the process of applying for a Job, anyways .......................

He made think hard about something I hadn't thought before, and that is:

What happens when you have a class that extends another class, that has a method that has the same name, return type and arguments as a method defined in an Interface that's also implemented by the extending class ?

like this I suppose:

It's really odd code I'd say. it even compiles.... but it's totally misleading,
Why it doesn't give any compiler errors?

As usual thanks for your time answering this question,
Best Regards,
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33130

Why is it misleading? B inherits A which happens to already take care of implementing the method required by the interface.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Rohan Kalbhor
Ranch Hand

Joined: Aug 18, 2006
Posts: 78
class B extends A implements Inter

Its not at all misleading,the above line has nothing to do with class A,

all parameters point to class B

from this line line, we mean to convey

class B extends A and

class B implements Inter

I hope that is what you feel misleading.

..............................<br />Exceptions are a part of possibility<br />Errors are a part of truth<br />................................
Jose Campana
Ranch Hand

Joined: May 28, 2007
Posts: 339
Oh, Good day to y'all
How are you Jeanne?

I suppose that if you put it in that way, then it's not misleading anymore.

I needed to read that!

And by the way, the misleading part I suppose would be seeing an Implementing class, that in this case should have at least one method in it, but it doesn't appear to have it, because it's not visually there. (something like that)

Have a nice day!
I agree. Here's the link:
subject: Curious case about inheritance & Interface
jQuery in Action, 3rd edition