This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Basic Question about extending/implementing  RSS feed

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why the following code doesnt show any conflict since both, method1 in iface1 and aclass1 have the same name and must be implemented by class test1a. It seems that test1a is implementing the aclass1 method and not the iface1, why?

Thanks in advance,
Fernando

 
Sheriff
Posts: 21459
96
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Your class is implementing both. The abstract method / interface method merely indicate that there should be a method called method1 that takes no parameters and returns void. And it does just that.
 
Marshal
Posts: 60127
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is only one way you could have a conflict: if the two methods did not have compatible intentions. I have amended your code to introduce such an incompatibility By the way: please use spaces, not tabs, for indenting.
 
lowercase baba
Bartender
Posts: 12627
50
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that even in Campbell's example, you can write code that compiles and runs - it just may not work the way everyone hopes.

When you implement an interface, all you are saying is "My class will have a definition/implementation for these methods".

When you extend an abstract class with a concrete class, you have to implement the abstract methods.

Note that by writing the method once, you have fulfilled your obligation to both.

If your mom says "You have to clean your room today", and your dad says "You have to clean your room today", as long as you clean it once, you have fulfilled both obligations.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!