It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Interface References? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


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

Interface References?

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 8795

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, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
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: 8795

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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Interface References?
 
Similar Threads
Do Interfaces implicilty subclass Object?
Extending Thread class
Multiple inheritance Topic, need answer!!!!!!!
An urgent doubt
interface