Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what exactly an interface object contains ?

 
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: 1599
  • 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
Pie
Posts: 12097
30
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: 2854
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic