What happens after the following code is compiled and run:

01: interface TheInterface {
02:    void print();
03: }
04: 
05: class TheClass implements TheInterface {
06:    public void print() {
07:       System.out.println("TheClass");
08:    }
09: }
10: 
11: public class ClassConversion {
12:    public static void main(String[] args) {
13:       TheClass c = new TheClass();
14:       TheInterface i = c;
15:       i.print();
16:    }
17: }
Explanation
Runtime typeof i will be TheClass so method TheClass.print() will be called. This is called polymorphism.
Java
Java Quiz
Start Quiz

or Read more about Java Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback