This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Curious case about inheritance & Interface" Watch "Curious case about inheritance & Interface" New topic
Author

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,
Jose
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30068
    
149

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


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, 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!
Jose
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Curious case about inheritance & Interface
 
Similar Threads
interface
from Khalid Mughal review questions
Local inner classes
Question on casting
I wonder how this happened