Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about interface

 
santhosh kumar vk
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,


can we use calss in interface, I went to one interview thay asked me how to use class in interface please tell me how to use the class in interface.
 
Ninad Kulkarni
Ranch Hand
Posts: 802
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ santhosh
UseAMeaningfulSubjectLine
Use Java forum for this question.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what you mean by "using a class in an interface."
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See my comment in http://www.coderanch.com/t/475635/Java-General/java/annotation
 
Hiram Nascimento
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Santhosh,

Yes, that's possible. I can give you an example from the Java Collections API.



Considering that an ArrayList (class) IS-A (implements) List (interface), you can call its methods by using a List interface reference.

Another example:


I could either create an IPod reference, but using the Player reference I get the benefits of polymorphism.

Does it make sense for you?

Hiram

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic