| Author |
Do Interface hold object states
|
ramya narayanan
Ranch Hand
Joined: Oct 06, 2008
Posts: 338
|
|
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.
|
 |
rakesh sugirtharaj
Ranch Hand
Joined: Dec 16, 2007
Posts: 151
|
|
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'.
|
Cheers!
RSR
|
 |
Amit Ghorpade
Bartender
Joined: Jun 06, 2007
Posts: 2552
|
|
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 ]
|
SCJP, SCWCD.
|Asking Good Questions|
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
|
Try it with the (skin) cast removed; it ought to make no difference to your application.
|
 |
 |
|
|
subject: Do Interface hold object states
|
|
|