QUESTION 26 Given: class Pizza { java.util.ArrayList toppings; public final void addTopping(String topping) { toppings.add(topping); } public void removeTopping(String topping) { toppings.remove(topping); }} public class PepperoniPizza extends Pizza { public void addTopping(String topping) { System.out.println("Cannot add Toppings"); } public static void main(String[] args) { Pizza pizza = new P..
QUESTION 25 Given that: Gadget has-a Sprocket and Gadget has-a Spring and Gadget is-a Widget and Widget has-a Sprocket Which two code fragments represent these relationships? (Choose two.) A. class Widget { Sprocket s; } class Gadget extends Widget { Spring s; } B. class Widget { } class Gadget extends Widget { Spring s1; Sprocket s2; } C. class Widget { Sprocket s1; Spring s2; } class Gadget ex..
QUESTION 24 A team of programmers is involved in reviewing a proposed design for a new utility class. After some discussion, they realize that the current design allows other classes to access methods in the utility class that should be accessible only to methods within the utility class itself. What design issue has the team discovered? A. Tight coupling B. Low cohesion C. High cohesion D. Loos..
QUESTION 23 Given: class Employee { String name; double baseSalary; Employee(String name, double baseSalary) { this.name = name; this.baseSalary = baseSalary; }} public class SalesPerson extends Employee { double commission; public SalesPerson(String name, double baseSalary, double commission) { // insert code here Line 13 }} Which two code fragments, inserted independently at line 13, will comp..
QUESTION 22 Given: abstract class A { abstract void a1(); void a2() { }} class B extends A { void a1() { } void a2() { }} class C extends B { void c1() { }} And: A x = new B(); C y = new C(); A z = new C(); What are four valid examples of polymorphic method calls? (Choose four.) A. x.a2(); B. z.a2(); C. z.c1(); D. z.a1(); E. y.c1(); F. x.a1(); Solution : ABDF plus imformation C. z.c1(); // Won't..
QUESTION 21 Given: class Animal { public String noise() { return "peep"; }} class Dog extends Animal { public String noise() { return "bark"; }} class Cat extends Animal { public String noise() { return "meow"; }} ... 30. Animal animal = new Dog(); 31. Cat cat = (Cat)animal; 32. System.out.println(cat.noise()); What is the result? A. peep B. bark C. meow D. Compilation fails. E. An exception is ..