1 / 6

Qwizdom Revision on inheritance and casting

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;.

vangie
Télécharger la présentation

Qwizdom Revision on inheritance and casting

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Qwizdom Revision on inheritance and casting

  2. 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

  3. 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

  4. 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

  5. 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

  6. 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

More Related