• Post Reply Bookmark Topic Watch Topic
  • New Topic

Do Interface hold object states  RSS feed

 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interface skin
{
}

class Human implements skin
{
int hands;
int legs;
public static void main(String[] args)
{
Human sai=new Human();
sai.hands=2;
sai.legs=2;
}
}


In some other class I assign these sai instance to interface skin
skin s=(skin)sai;


Now when i'm assigning an object instance(sai) to an interface(skin) does the interface holds the object's states & methods.
Regards.
 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you are just giving a reference. Still it is an object(at heart ). You can call 'sai' as sai or 'hey dude!' but he is still sai,right? A generel info here: Generally (and also logically) interfaces represent functionality. So usually you would have 'Skinnable' than 'skin'.
 
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In addition, when a class implements an interface, the ISA relation is achieved.

Sometimes you'll come across code like



where Implementable is an interface and AClass is a class that implements it.
[ November 05, 2008: Message edited by: Amit Ghorpade ]
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try it with the (skin) cast removed; it ought to make no difference to your application.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!