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 messaging queue in java?

491


What is jpa project?

467


Why java is better than node.js?

467


How do I open java console?

495


Can I have multiple main methods in the same class?

477






What is the use of flatmap in java 8?

458


i have client interview in TCS.client is CITI BANK.how to face it,what type of questions they will ask,please tell send me to kumar525job@gmail.com

13070


What is maven in java?

455


can a program use more than one command-line argument?

474


What is csrf in java?

479


What does el mean in java?

513


What is class forname java?

474


Which version of jdk is required for netbeans 8.0 2?

431


What is cache in java?

494


Where are group policies stored? : java security

486