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

Java prints out a ton of digits when I system.out.println() a double. How can I format it so it displays only 3 digits after the decimal place?

1 Answers  


What is exe file in java?

1 Answers  


What is stateless in java?

1 Answers  


What are the types of cookies in java?

1 Answers  


How do you run an executable jar file?

1 Answers  


What is entitymanager in java?

1 Answers  


What are the rules regarding quotation marks?

1 Answers  


why the sleep method does not leave the lock and wait method leave the lock

4 Answers  


what are the steps in JDBC connectivity..???

1 Answers   IBM, SoftCom, TCS,


How do I enable java in google chrome?

1 Answers  


What is default constructor in java?

1 Answers  


Can I have multiple main methods in the same class?

1 Answers  


Categories