• Post Reply Bookmark Topic Watch Topic
  • New Topic

Interface  RSS feed

 
Nickk Singhal
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If we write same methods in different interface then what will happen??
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing. What do you think will happen?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The usual answer we give to such questions is "what happened when you tried it?"

But if you think about it, an interface is simply a list of methods. when you write a class that says "implements X,Y", you are saying that this class WILL implement whatever methods are defined. If both interface X and Y have a method listed, when your class implements it, you have satisfied the requirements. It's like if you tell your mom "i'll clean my room tomorrow", and you tell your dad "I'll clean my room tomorrow", you only have to clean it once to satisfy both.

Now, if the methods are supposed to do different things, you are in trouble.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nickk Singhal wrote:If we write same methods in different interface then what will happen??

As Bear said: nothing. However, if you write a class that implements both interfaces, you may run into conflicts as to it's meaning.

Winston
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!