File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interface References?

 
Joe Harry
Ranch Hand
Posts: 10045
3
Eclipse IDE Mac PPC Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
yogesh sood
Ranch Hand
Posts: 108
  • 0
  • Mark post as helpful
  • send pies
  • 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 Harry
Ranch Hand
Posts: 10045
3
Eclipse IDE Mac PPC Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Yogesh,

Thanks for the reply.

Regards,
Jothi Shankar Kumar. S
 
wise owen
Ranch Hand
Posts: 2023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this thread also.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic