File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Interface References? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Interface References?" Watch "Interface References?" New topic

Interface References?

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9344

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,

Jothi Shankar Kumar. S

SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
yogesh sood
Ranch Hand

Joined: Aug 31, 2000
Posts: 108

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

If its green its biology if its stinkks its chemistry if it has numbers it is Maths and if it doesn't work its TECHNOLOGY
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9344

Hi Yogesh,

Thanks for the reply.

Jothi Shankar Kumar. S
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
Check this thread also.
wood burning stoves
subject: Interface References?
Similar Threads
Do Interfaces implicilty subclass Object?
Extending Thread class
An urgent doubt
Multiple inheritance Topic, need answer!!!!!!!