Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

what exactly an interface object contains ?  RSS feed

 
RohitR Kulkarni
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what exactly an interface object contains when we declare it to achieve correct method invocation?
how it correctly works?
suppose i have two interfaces each having one method with same method name.
a class implements this interface. how using an interface object and assigning that object a class object calls the method from that interface only???
 
Akhilesh Trivedi
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by RohitR Kulkarni:
what exactly an interface object contains when we declare it to achieve correct method invocation?
how it correctly works?
suppose i have two interfaces each having one method with same method name.
a class implements this interface. how using an interface object and assigning that object a class object calls the method from that interface only???


An interface is just a specification, a skeleton, there is no body, there is no implementation. You would feel its importance only at runtime.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12527
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
an interface declares a set of methods the implementing class MUST define. it simply says "any and all classes that implement me will have the following methods with the following signatures".

If you have two interfaces that both declare the same method, it's not a problem. the one method you write will satisfy that part of both interfaces. you kind of get two-for-one.
 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the subject is a bit confusing one, there is no such thing as interface object there is only a reference of the interface type that holds an object of the implementing class.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!