o Consider variable declarations C x and D y where class C e

o Consider variable declarations C x and D y where class C extends D. Page 177 superclass why is it illegal to perform an assignment x-y? bul \', no! 1s lega eye what is the potential problem with x = (C) y at execution time? he progron will be confuse d on which volue tis the potental ri ko tc ate

Solution

a) It is illegal to perform assignment x = y, where x is of class C and y is of class D because subclass C might have more member fields other than those in D that are not defined in D.

b) This is because C object is also a D object but not all D objects (superclass) are going to be C objects. This means you cannot convert a D object to a C object.

(A simple analogy to think about this is that all thumbs are fingers but all fingers are not necessarily thmbs).

 o Consider variable declarations C x and D y where class C extends D. Page 177 superclass why is it illegal to perform an assignment x-y? bul \', no! 1s lega e

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site