60 likes | 155 Vues
Qwizdom Revision on inheritance and casting. Study the following class diagram and code. Which one of the following is correct?. Employee. Employee e; Manager m = new Manager(); e = m;.
E N D
Study the following class diagram and code. Which one of the following is correct? Employee Employee e; Manager m = new Manager(); e = m; • This will compile because variable m is of type Manager which is a subtype of Employee, hence polymorphic assignment • This will not compile because m must be the same type as e • This will compile but throw an exception at runtime • I don’t know Manager Contractor
Study the following class diagram and code. Which one of the following is correct? Employee Manager m; Contractor c = new Contractor(); m = c; • This will compile since both m and c are related through the common Employeesupertype • This will compile but fail at runtime • This will not compile since c is neither the same type as m nor a subtype of m, so polymorphic assignment is disallowed • I don’t know Manager Contractor
Study the following class diagram and code. Which one of the following is correct? Employee Employee e = new Employee(); Manager m; m = e; • This will compile since m is a subtype of Employee • This will not compile since it breaks the polymorphic assignment rule • This will compile but fail at runtime • I don’t know Manager Contractor
Study the following class diagram and code. Which one of the following is correct? Employee Employee e = new Employee(); Manager m; m = (Manager)e; • This will not compile since it breaks the polymorphic assignment rule • This will compile but fail at runtime • This will compile and run correctly • I don’t know Manager Contractor
Study the following class diagram and code. Which one of the following is correct? Employee • This will not compile since it breaks the polymorphic assignment rule • This will compile but fail at runtime • This will compile and run correctly • I don’t know Employee e = new Manager(); Manager m; m = (Manager)e; Manager Contractor