Question: Question 1 . ( 4 0 pts . ) Assume the following Java subtyping hierarchy: Integer is a subtype of Number, PositiveInteger is a subtype
Question 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;
senpushn; assume sen and n are not null
ssi new Stack;
ssi.pusho; assume o is not null
o senpeek; assume sen is not null
i ssi.peek; assume ssi is not null
sen new Stack;
senpushpi; 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
