• Post Reply Bookmark Topic Watch Topic
  • New Topic

Relationship between Interface and its implementation  RSS feed

 
yaswanth yash
Greenhorn
Posts: 12
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you explain me the relationship between Interface and its implementation classes?
And I want to know the usage of reference variables & objects for the methods in interfaces and its Implementation classes.
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at this thread, which is about the same question. That will probably help
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what you mean by your second sentence, but the relationship is that the interface defines a set of public methods that the concrete implementing classes must implement.

In terms of meaning, there is an IS-A relationship. For example, if a class implements Runnable, then it IS runnable. If a class implements MouseListener then it IS a class that can respond to mouse events.
 
Randall Twede
Ranch Hand
Posts: 4696
8
Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this may help with the second part of the question. the following code is from a program that has an interface called Problem and many classes that implement it.

i declare a Problem variable called choice. and call both it's 2 methods. of course each class implements these methods differently.
 
Ankush Kaundal
Ranch Hand
Posts: 36
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See in the Interface you can declare the methods which the implementing class should be giving the definition for those methods, however if you do not want to give implementation for all the methods then you can declare your class as an abstract class.
Also by using the reference of the Interface type and the object of the class type you will be doing the polymorphism and which will decide at run-time which method to call according to your implementation and also to note that the method to be called depends on type of object and the variable to be used depends on type of reference.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!