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 |
What is lambda used for?
What is the difference between java se and java ee?
What is java api?
If you’re overriding the method equals() of an object, which other method you might also consider?
What is a cookie in java?
Can we write lambda without functional interface?
Can a method be static and synchronized?
When is static variable loaded? Is it at compile time or runtime? When exactly a static block is loaded in java?
How common are security breaches? : java security
What is war file in java?
What is cmp in java?
What is savepoint in java?