wood burning stoves 2.0*
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


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Interface References?" Watch "Interface References?" New topic
Author

Interface References?

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9395
    
    2

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


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
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


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: 9395
    
    2

Hi Yogesh,

Thanks for the reply.

Regards,
Jothi Shankar Kumar. S
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
Check this thread also.
 
GeeCON Prague 2014
 
subject: Interface References?