• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Curious case about inheritance & Interface

 
Jose Campana
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34396
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jose,
Why is it misleading? B inherits A which happens to already take care of implementing the method required by the interface.
 
Rohan Kalbhor
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jose Campana
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic