Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

R9.12 Suppose C is a class that implements the interfaces I and J. Which of the following assignments require a cast? C c = .

R9.12 Suppose C is a class that implements the interfaces I and J. Which of the following assignments require a cast?

C c = . . .; I i = . . .; J j = . . .;

a. c = i; b. j = c; c. i = j;

R9.13 Suppose C is a class that implements the interfaces I and J, and i is declared as

I i = new C();

Which of the following statements will throw an exception?

a. C c = (C) i; b. J j = (J) i; c. i = (I) null;

R9.14 Suppose the class Sandwich implements the Edible interface, and you are given the variable declarations

Sandwich sub = new Sandwich(); Rectangle cerealBox = new Rectangle(5, 10, 20, 30); Edible e = null;

Which of the following assignment statements are legal?

a. e = sub; b. sub = e; c. sub = (Sandwich) e; d. sub = (Sandwich) cerealBox; e. e = cerealBox; f. e = (Edible) cerealBox; g. e = (Rectangle) cerealBox; h. e = (Rectangle) null;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions