Question: Question 1 . ( 4 0 pts . ) Assume the following Java subtyping hierarchy: Integer is a subtype of Number, PositiveInteger is a subtype

Question 1.(40 pts.) Assume the following Java subtyping hierarchy: Integer is a subtype of Number, PositiveInteger is a subtype of Integer, and NegativeInteger is a subtype of Integer. Integer implements the respective generic Comparable
interface.
Given the following declarations of variables:
Object o;
Number n;
Integer i;
PositiveInteger pi;
NegativeInteger ni;
Stack sen;
Stack ssi;
Which of the following lines are legal? Treating each snippet of code individually, select Legal or Not legal for each one:
sen = ssi; // assume ssi has been initialized
sen = new Stack();
sen.push(n); // assume sen and n are not null
ssi = new Stack();
ssi.push(o); // assume o is not null
o = sen.peek(); // assume sen is not null
i = ssi.peek(); // assume ssi is not null
sen = new Stack();
sen.push(pi); // assume pi is not null
ssi = sen; // assume sen has been initialized

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!