Gate CS-2003 Question Paper With Solutions

Q. 22 Consider the following class definitions in a hypothetical object oriented language
that supports inheritance and uses dynamic binding. The language should not be
assumed to be either Java or C++, thought the syntax is similar

Gate CS-2003 Question Paper With Solutions

Now consider the following program fragment:
P x =new Q();
Q y =new Q();
P z =new Q();
x.f (1);((P)y). f (1);z.f (1);
Here ((P)y) denotes a typecast of y to P. The output produced by executing the
above program fragment will be
(A) 1 2 1
(B) 2 1 1
(C) 2 1 2
(D) 2 2 2

Answer: (D)

Explanation:

Gate CS-2003 Question Paper With Solutions Gate CS-2003 Question Paper With Solutions

Learn More:   Gate EC-2017-2 Question Paper With Solutions

LEAVE A REPLY

Please enter your comment!
Please enter your name here