• 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

Interface References?

 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers,

Considering the code below, can anyone tell me what is the use of Interface reference variable? I mean how will it be of help when there is a class that implements that interface? Has it got anything to do with casting?

interface Sample{int j=10;}

public class Main implements Sample{

public static void main(String [] args){
Sample joe=null;
System.out.println(Sample.j); //joe.j also prints 10???

}

}

Thanks in advance,

Regards,
Jothi Shankar Kumar. S
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Variables defined in Interface are "public static final", therefore you can get value of interface variable by prefixing any one given below

1. Name of interface
2. Name of class implementing interface
3. Reference Variable of class implementing interface
4. Reference variable of Interface
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Yogesh,

Thanks for the reply.

Regards,
Jothi Shankar Kumar. S
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check this thread also.
 
reply
    Bookmark Topic Watch Topic
  • New Topic