final-sample-4 - CSE 143 Sample Final Exam#4 1 Inheritance...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 143 Sample Final Exam #4 1. Inheritance and Polymorphism . Consider the following classes ( System.out.println has been abbreviated as S.o.pln ): public class Eye extends Mouth { public void method1() { S.o.pln("Eye 1"); super.method1(); } } public class Mouth { public void method1() { S.o.pln("Mouth 1"); } public void method2() { S.o.pln("Mouth 2"); method1(); } } public class Nose extends Eye { public void method1() { S.o.pln("Nose 1"); } public void method3() { S.o.pln("Nose 3"); } } public class Ear extends Eye { public void method2() { S.o.pln("Ear 2"); } public void method3() { S.o.pln("Ear 3"); } } The following variables are defined: Mouth var1 = new Nose(); Ear var2 = new Ear(); Mouth var3 = new Eye(); Object var4 = new Mouth(); Eye var5 = new Nose(); Mouth var6 = new Ear(); In the table below, indicate in the right-hand column the output produced by the statement in the left-hand column. If the statement produces more than one line of output, indicate the line breaks with slashes as in "a / b / c" to indicate three lines of output with "a" followed by "b" followed by "c". If the statement causes an error, fill in the right-hand column with the phrase "error" to indicate this. Statement var1.method1(); var2.method1(); var3.method1(); var1.method2(); var2.method2(); var3.method2(); var4.method2(); var5.method2(); var6.method2(); var1.method3(); var2.method3(); var3.method3(); ((Nose) var5).method3(); ((Eye) var1).method1(); ((Eye) var4).method1(); ((Nose) var1).method3(); ((Mouth) var4).method1(); ((Ear) var5).method3(); ((Eye) var6).method3(); ((Mouth) var4).method2(); Output ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
2. Inheritance and Comparable . You have been asked to extend the ArrayIntList class that we have been studying. Recall that it includes the following public constructors and methods: public ArrayIntList() constructs an empty list with default capacity public ArrayIntList(int capacity) constructs an empty list with the given capacity public void add(int value) adds given value to end of list public void add(int index, int value) adds given value at given index public boolean contains(int value) returns whether value occurs anywhere in the list public int get(int index) returns value at given index public int indexOf(int value) index of first occurrence of value; -1 if not found public boolean isEmpty()
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 7

final-sample-4 - CSE 143 Sample Final Exam#4 1 Inheritance...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online