1. CH 9, self-check: Problem 1, pg. 634 What is code reuse? How does inheritance help achieve code reuse? 2. CH 9, self-check: problem 3, pg. 634 Which of the following is the correct syntax to indicate that class A is a subclass of B? a. public class B extends A { b. public class A : super B { c. public A(super B) { d. public class A extends B { e. public A implements B { 3. CH 9, self-check: problem 4, pg. 635 Consider the following classes: public class Vehicle { } public class Car extends Vehicle { } public class SUV extends Car { } Which of the following are legal statements (assuming these classes all have constructors with no arguments)? a . Vehicle v = new Car(); b. Vehicle v = new SUV(); c. Car c = new SUV(); d. SUV s = new SUV(); e. SUV s = new Car(); f. Car c = new Vehicle(); 4. CH 9, self-check: problem 5, pg. 635 Explain the difference between the this keyword and the super keyword. When should each be used? 5. CH 9, self-check: problem 6, pg. 635 For the next three problems consider the following class: // Represents a university student. public class Student { private String name; private int age; public Student(String name, int age) { this.name = name; this.age = age; } public void setAge(int age) { this.age = age; } } Also consider the following partial implementation of a subclass of Student to represent undergraduate students at a university: public class UndergraduateStudent extends Student { private int year; . . . } Can the code in the UndergraduateStudent class access the name and age fields it inherits from Student? Can it call the setAge method? 6. CH 9, self-check: problem 11, pg. 637 Assume that the following classes have been defined (from section 9.3, pp. 600-601): public class A { public void method1() { System.out.println(A 1); ` } public void method2() { System.out.println(A 2); } public String toString() { return A; } } public class B extends A { public void method2() { System.out.println(B 2); } } public class C extends A { public void method1() { System.out.println(C 1); } public String toString() { return C; } } public class D extends C { public void method2() { System.out.println(D 2); } } What is the output produced by the following code fragment? public static void main(String[] args) { A[] elements = {new B(), new D(), new A(), new C()}; for (int i = 0; i < elements.length; i++) { elements[i].method2(); System.out.println(elements[i]); elements[i].method1(); System.out.println(); } } 7. CH 9, self-check: problem 12, pp. 637-638 Assume that the following classes have been defined: public class Flute extends Blue { public void method2() { System.out.println(flute 2); } public String toString() { return flute; } } public class Blue extends Moo { public void method1() { System.out.println(blue 1); ` } } public class Shoe extends Flute { public void method1() { System.out.println(shoe 1); ` } } public class Moo { public void method1() { System.out.println(moo 1); ` } public void method2() { System.out.println(moo 2); } public String toString() { return moo; } } What is the output produced by the following code fragment? public static void main(String[] args) { Moo[] elements = {new Shoe(), new Flute(), new Moo(), new Blue()}; for (int i = 0; i < elements.length; i++) { System.out.println(elements[i]); elements[i].method1(); elements[i].method2(); System.out.println(); } } 8. CH 9, exercises: problem 1, pg. 642. Write the class Marketer to accompany the other law firm classes described in this chapter . Marketers make $50,000 ($10,000 more than general employees) and have an additional method called advertise that prints Act now, while supplies last! Make sure to interact with the superclass as appropriate. Note that the textbook website has a Marketer.java , but its not quite right to fit with Employee.java in the text itself, so fix it up to do so. 9. CH 9, exercises: Problem 5, pg. 643. For the next two problems, consider the task of representing ...
Looking for a solution written from scratch with No plagiarism and No AI?
WHY CHOOSE US?
We deliver quality original papers |
Our experts write quality original papers using academic databases.We dont use AI in our work. We refund your money if AI is detected |
Free revisions |
We offer our clients multiple free revisions just to ensure you get what you want. |
Discounted prices |
All our prices are discounted which makes it affordable to you. Use code FIRST15 to get your discount |
100% originality |
We deliver papers that are written from scratch to deliver 100% originality. Our papers are free from plagiarism and NO similarity.We have ZERO TOLERANCE TO USE OF AI |
On-time delivery |
We will deliver your paper on time even on short notice or short deadline, overnight essay or even an urgent essay |