Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Copying of work (texts, lab results etc.) from other students/groups or from other sources is not allowe Assignments must be submitted on the due dates.

image text in transcribed

Copying of work (texts, lab results etc.) from other students/groups or from other sources is not allowe Assignments must be submitted on the due dates. Some points will be deducted for late submissions. Assignments submitted three days after the due date will not be accepted. 1. Order these items into an inheritance hierarchy: apple, ice cream, bread, fruit, food item, cereal, orange, dessert, chocolate mousse, baguette. 2. Write a few lines of code that result in a situation where a variable x has the static type T and the dynamic type D 3. Assume that we have four classes: Person, Teacher, Student, and PhDStudent. Teacherand Studentare both subclasses of Person. PhDStudentis a subclass of Student. a. Which of the following assignments are legal, and why or why not? i. Person p1 = new Student () ; ii. Person p2= new PhDStudent(); iii. PhDStudent phd 1= new Student () ; iv. Teacher t1= new Person(); v. Student s 1= new PhDStudent(); b. Suppose that we have the following legal declarations and assignments: i. Person p1 = new Person( () ; ii. Person p2 = new Person () ; iii. PhDStudent phd 1= new PhDStudent(); iv. Teacher t1= new Teacher( ); v. Student s 1= new Student () ; Based on those just mentioned, which of the following assignments are legal, and why or why not? i. s1=p1; ii. s1=p2; iii. p1=s1; iv. t1=s1; v. s 1= phd 1 ; vi. phd 1=s1; 4. Draw an inheritance hierarchy representing parts of a computer system (processor, memory, disk drive, DVD drive, printer, scanner, keyboard, mouse, etc.). 5. Look at the code below. You have four classes (O,X,T, and M) and a variable of each of these. a. O; b. Xx; c. Tt; d. Mm; The following assignments are all legal (assume that they all compile): i. m=t; ii. m=x; iii. o=t; The following assignments are all illegal (they cause compiler errors): i. o=m; ii. o=x; iii. x=0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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