when Can an object reference be cast to an interface reference?



when Can an object reference be cast to an interface reference?..

Answer / praveen kumar

.An interface reference can point to any object of a class that implements this interface i.e. see the example below:

interface Foo{
void display();
}

public class TestFoo implements Foo{

void display(){
System.out.println(“Hello World”);
}

public static void main(String[] args){
Foo foo = new TestFoo();
foo.display();
}

}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Java Related AllOther Interview Questions

how ahstraction is the property of oops,this is also in c and c++ ex. printf function which is also hide the unnecessary data,so what is the difference ? and does c++ fallow the abstraction?

0 Answers  


What is stateful in java?

0 Answers  


What are the rules regarding quotation marks?

0 Answers  


What does el mean in java?

0 Answers  


Is java built on c?

0 Answers  






What is a singleton in java?

0 Answers  


What about javascript? : java security

0 Answers  


Can the main method be declared final?

0 Answers  


What is jsr in java?

0 Answers  


What is exe file in java?

0 Answers  


what is the function of OS

3 Answers  


Do I need jdk or jre?

0 Answers  


Categories