• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Do Interface hold object states

 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try it with the (skin) cast removed; it ought to make no difference to your application.
 
I'm full of tinier men! And a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic