File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Do Interface hold object states Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Do Interface hold object states" Watch "Do Interface hold object states" New topic
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
    
    2

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
    
    4
Try it with the (skin) cast removed; it ought to make no difference to your application.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Do Interface hold object states
 
Similar Threads
exercise in java
Dynamic Constructor call
newbie in trouble about instanceof
cannot find symbol?......wats happening???
Getting the type of variable instance