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

What is persistence xml in java?

0 Answers  


explain isalive() method under thread class?

0 Answers  


What is cmp in java?

0 Answers  


What is the difference between jar and executable jar?

0 Answers  


Can an application have multiple classes having main method?

0 Answers  


What are tlds in java?

0 Answers  


What is injection in java?

0 Answers  


If you’re overriding the method equals() of an object, which other method you might also consider?

0 Answers  


What is flatmap in rxjs?

0 Answers  


What is tuple2?

0 Answers  


What are anonymous methods and lambda expression?

0 Answers  


What is the difference between lambda expression and anonymous methods?

0 Answers  


Categories