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 do you run an executable jar file?

0 Answers  


What is an action class in java?

0 Answers  


Can the main method be declared final?

0 Answers  


What is jsr in java?

0 Answers  


Why do we need new date and time api in java se 8?

0 Answers  






Which is best framework in java?

0 Answers  


What is tier in java?

0 Answers  


How do javabeans work?

0 Answers  


What's a code group? : java security

0 Answers  


What is a service layer in java?

0 Answers  


What is the use of flatmap in java 8?

0 Answers  


What is the difference between lambda expression and anonymous methods?

0 Answers  


Categories