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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What is meant by java se?

523


What is interceptor in java?

470


When a thread is created and started, what is its initial state?

549


What kind of thread is the garbage collector thread?

508


Topic- looping,function overloading,nesting ,polymorphism. Aim - to write a function with a name buzz-buds,that will check whether the given numbers are buddies or not on the basis of no. of parameters passed during function calling.

1602






What's the difference between authentication and authorization? : java security

503


Why are lambda functions called lambda?

478


How do I install java on windows?

464


What is an entity in java?

480


What is static class in java?

504


What is the use of servlet in java?

506


What is dao in java?

505


Can we write lambda without functional interface?

453


What is lambda value?

483


What is gui in java with examples?

475