Question: A library defines a generic class Foo in a Java-like language. A users program declares a class C and subclasses it as class D, creating
A library defines a generic class Foo in a Java-like language. A user’s program declares a class C and subclasses it as class D, creating variables fc and fd of types Foo and Foo respectively. (i) Construct a declaration of Foo along with a program of the above form containing the assignment fc=fd which, if this statement were legal, would be the cause of a later run-time error when executed. (ii) How might the language syntax be changed to optionally express that the above assignment is to be allowed, indicating any compensating restrictions required for the declaration of Foo or fc to avoid run-time errors. (iii) How do Java arrays of type T[] fit in with your answer to Part (c)(i)?
Step by Step Solution
3.40 Rating (153 Votes )
There are 3 Steps involved in it
The detailed answer for the above question is provided below ANSWER i Declaration and Program with Runtime Error typescript Declaration of generic cla... View full answer
Get step-by-step solutions from verified subject matter experts
