CSA Chapter 9 review

¡Supera tus tareas y exámenes ahora con Quizwiz!

In Java how many parents can a class have? A. 0 B. 1 C. 2 D. infinite

B. 1

public class Animal { public void eat() { /* implementation not shown */ } // constructors and other methods not shown } public class Tiger extends Animal { public void roar() { /* implementation not shown */ } // constructors and other methods not shown } Assume that the following declaration appears in a client class. Animal a = new Tiger(); Which of the following statements would compile without error? I. a.eat(); II. a.roar(); III.((Tiger) a).roar();

D - I and III only

public class Bike { private int numWheels = 2; // No constructor defined } public class EBike extends Bike { private int numBatteries; public EBike(int batteries) { numBatteries = batteries; } } The following code segment appears in a method in a class other than Bike or EBike. EBike eB = new EBike(4); Which of the following best describes the effect of executing the code segment?

A - An implicit call to the zero-parameter Bike constructor initializes the instance variable numWheels. The instance variablenumBatteries is initialized using the value of the parameter batteries.

Consider the following class declarations. Assume that each class has a no-argument constructor. public class Food { /* implementation not shown */ } public class Snack extends Food { /* implementation not shown */ } public class Pizza extends Snack { /* implementation not shown */ } Which of the following declarations will compile without error?

A - Food tacos = new Snack();

Consider the following two classes. Public class A public void show() What is printed as a result of executing the following code segment?

B - B

public class First { public String name() { return "First"; } } public class Second extends First { public void whoRules() { System.out.print(super.name() + " rules"); System.out.println(" but " + name() + " is even better"); } public String name() { return "Second"; } } public class Third extends Second { public String name() { return "Third"; } } Consider the following code segment. Second varSecond = new Second(); Third varThird = new Third(); varSecond.whoRules(); varThird.whoRules(); What is printed as a result of executing the code segment?

B - First rules but Second is even better First rules but Third is even better

What is the output from running the main method in the Student class? public class Student { public String getFood() { return "Pizza"; } public String getInfo() { return this.getFood(); } public static void main(String[] args) { Student s1 = new GradStudent(); s1.getInfo(); } } class GradStudent extends Student { public String getFood() { return "Taco"; } } A. Pizza B. Taco C. You will get a compile time error D. You will get a run-time error

B. Taco

Which of the following declarations in Person would correctly overload the getFoodmethod in Person? public class Person { private String name = null; public Person(String theName) { name = theName; } public String getFood() { return "Hamburger"; } } public class Student extends Person { private int id; private static int nextId = 0; public Student(String theName) { super(theName); id = nextId; nextId++; } public int getId() {return id;} public void setId (int theId) { this.id = theId; } } A. public void getFood() B. public String getFood(int quantity) C. public String getFood()

B. public String getFood(int quantity)

public class Bird { private int beakStrength; public Bird(int input) { beakStrength = input; } public void setBeakStrength(int strength) { beakStrength = strength; } } public class Hawk extends Bird { private int talonStrength; public Hawk(int talon, int beak) { super(beak); talonStrength = talon; } } The following statement appears in a method in another class. Bird b = new Hawk(5, 8); Which of the following best describes the effect of executing the statement?

D - The Bird variable b is instantiated as a Hawk. The call super(beak) invokes the Bird constructor and initializes the instance variable beakStrength with the value from the parameter beak. The instance variable talonStrength is then initialized with the value from the parameter talon.

public class A { private int al; public void methodA() { methodB(); // Statement I } } public class B extends A { public void methodB() { methodA(); // Statement II al = 0; // Statement III } }

D - I and III

Public class Dog public void act()

D - run eat bark sleep

If you don't specify the parent class in a class declaration which of the following is true? A. It doesn't have a parent class. B. It inherits from the Object class. C. It inherits from the Default class. D. It inherits from the Parent class.

B. It inherits from the Object class.

If I had a class ParkingGarage should it inherit from the class Vehicle? A. Yes B. No

B. No

A class Student inherits from the superclass Person. Which of the following assignment statements will give a compiler error? A. Person p = new Person(); B. Person p = new Student(); C. Student s = new Student(); D. Student s = new Person();

D. Student s = new Person();

Public class point Which of these constructors would be legal for the NamedPoint class?

D - I and III only

What Java keyword is used to set up an inheritance relationship between a subclass and a superclass? A. superclass B. parent C. extends D. class

C. extends

When designing a class hierarchy, which of the following should be true of a superclass?

A - A superclass should contain the data and functionality that are common to all subclasses that inherit from the superclass.

Consider the following class definitions. public class Robot { private int servoCount; public int getServoCount() { return servoCount; } public void setServoCount(int in) { servoCount = in; } } public class Android extends Robot { private int servoCount; public Android(int initVal) { setServoCount(initVal); } public int getServoCount() { return super.getServoCount(); } public int getLocal() { return servoCount; } public void setServoCount(int in) { super.setServoCount(in); } public void setLocal(int in) { servoCount = in; } } The following code segment appears in a method in another class. int x = 10; int y = 20; /* missing code */ Which of the following code segments can be used to replace /* missing code */ so that the value 20 will be printed?

A - Android a = new Android(x); a.setServoCount(y); System.out.println(a.getServoCount());

public class Membership { private String id; public Membership(String input) { id = input; } // Rest of definition not shown } public class FamilyMembership extends Membership { private int numberInFamily = 2; public FamilyMembership(String input) { super(input); } public FamilyMembership(String input, int n) { super(input); numberInFamily = n; } // Rest of definition not shown } public class IndividualMembership extends Membership { public IndividualMembership(String input) { super(input); } // Rest of definition not shown } The following code segment occurs in a class other than Membership,FamilyMembership, or IndividualMembership. FamilyMembership m1 = new Membership("123"); // Line 1 Membership m2 = new IndividualMembership("456"); // Line 2 Membership m3 = new FamilyMembership("789"); // Line 3 FamilyMembership m4 = new FamilyMembership("987", 3); // Line 4 Membership m5 = new Membership("374"); // Line 5 Which of the following best explains why the code segment does not compile?

A - In line 1, m1 cannot be declared as typeFamilyMembership and instantiated as a Membership object.

public class A { public String message(int i) { return "A" + i; } } public class B extends A { public String message(int i) { return "B" + i; } } The following code segment appears in a class other than A or B. A obj1 = new B(); // Line 1 B obj2 = new B(); // Line 2 System.out.println(obj1.message(3)); // Line 3 System.out.println(obj2.message(2)); // Line 4 Which of the following best explains the difference, if any, in the behavior of the code segment that will result from removing the message method from classA ?

A - The statement in line 3 will cause a compiler error because themessage method for obj1 cannot be found.

A car dealership needs a program to store information about the cars for sale. For each car, they want to keep track of the following information: number of doors (2 or 4), whether the car has air conditioning, and its average number of miles per gallon. Which of the following is the best object-oriented program design?

A - Use one class, Car, with three instance variables: int numDoors, boolean hasAir, and double milesPerGallon.

public class Document { private int pageCount; private int chapterCount; public Document(int p, int c) { pageCount = p; chapterCount = c; } public String toString() { return pageCount + " " + chapterCount; } } The following code segment, which is intended to print the page and chapter counts of a Document object, appears in a class other than Document. Document d = new Document(245, 16); System.out.println( /* missing code */ ); Which of the following can be used as a replacement for /* missing code */ so the code segment works as intended?

A - d.toString()

What is the output from running the main method in the Car class? public class Car { private int fuel; public Car() { fuel = 0; } public Car(int g) { fuel = g; } public void addFuel() { fuel++; } public void display() { System.out.print(fuel + " "); } public static void main(String[] args) { Car car = new Car(5); Car fastCar = new RaceCar(5); car.display(); car.addFuel(); car.display(); fastCar.display(); fastCar.addFuel(); fastCar.display(); } } class RaceCar extends Car { public RaceCar(int g) { super(2*g); } } A. 5 6 10 11 B. 5 6 5 6 C. 10 11 10 11 D. The code won't compile.

A. 5 6 10 11

If the class Vehicle has the instance fields make and model and the class Car inherits from the class Vehicle, will a car object have a make and model? A. Yes B. No

A. Yes

Given the following class declarations, and assuming that the following declaration appears in a client program: Base b = new Derived();, what is the result of the call b.methodOne();? public class Base { public void methodOne() { System.out.print("A"); methodTwo(); } public void methodTwo() { System.out.print("B"); } } public class Derived extends Base { public void methodOne() { super.methodOne(); System.out.print("C"); } public void methodTwo() { super.methodTwo(); System.out.print("D"); } } A. AB B. ABDC C. ABCD D. ABC E. Nothing is printed.

B. ABDC

Given the class definitions of MPoint and NamedPoint below, which of the constructors that follow (labeled I, II, and III) would be valid in the NamedPoint class? class MPoint { private int myX; // coordinates private int myY; public MPoint( ) { myX = 0; myY = 0; } public MPoint(int a, int b) { myX = a; myY = b; } // ... other methods not shown } public class NamedPoint extends MPoint { private String myName; // constructors go here // ... other methods not shown } // Proposed constructors for this class: I. public NamedPoint() { myName = ""; } II. public NamedPoint(int d1, int d2, String name) { myX = d1; myY = d2; myName = name; } III. public NamedPoint(int d1, int d2, String name) { super(d1, d2); myName = name; } A. I only B. I and III C. II only D. III only

B. I and III

Which of the following reasons for using an inheritance hierarchy are valid? Object methods from a superclass can be used in a subclass without rewriting or copying code. Objects from subclasses can be passed as arguments to a method that takes an argument of the parent type. Objects from subclasses can be stored in the same array of the parent type. All of the above None of the above A. V B. IV C. I and II D. I and III E. I only

B. IV

Given the following class definitions and a declaration of Book b = new Dictionary which of the following will cause a compile-time error? public class Book { public String getISBN() { // implementation not shown } // constructors, fields, and other methods not shown } public class Dictionary extends Book { public String getDefinition() { // implementation not shown } } A. b.getISBN(); B. b.getDefintion(); C. ((Dictionary) b).getDefinition();

B. b.getDefintion();

public class Game { private String name; public Game(String n) { name = n; } // Rest of definition not shown } public class BoardGame extends Game { public BoardGame(String n) { super(n); } // Rest of definition not shown } The following code segment appears in a class other than Game orBoardGame. Game g1 = new BoardGame("checkers"); BoardGame g2 = new Game("chess"); ArrayList<Game> My_Games = new ArrayList(); My_Games.add(g1); My_Games.add(g2); Which of the following best explains why the code segment does not compile?

B - A Game object cannot be assigned to the BoardGame reference g2.

public class ClassA { public String getValue() { return "A"; } public void showValue() { System.out.print(getValue()); } } public class ClassB extends ClassA { public String getValue() { return "B"; } } The following code segment appears in a class other than ClassA or ClassB. ClassA obj = new ClassB(); obj.showValue(); What, if anything, is printed when the code segment is executed?

B - B

public class First { public String name() { return "First"; } } public class Second extends First { public void whoRules() { System.out.print(super.name() + " rules"); System.out.println(" but " + name() + " is even better"); } public String name() { return "Second"; } } public class Third extends Second { public String name() { return "Third"; } } Consider the following code segment. /* SomeType1 */ varA = new Second();/* SomeType2 */ varB = new Third(); varA.whoRules();varB.whoRules(); *table here*

B - II only

When designing classes, which of the following would be the best reason to use inheritance?

B - Inheritance allows the creation of a subclass that can use the methods of its superclass without rewriting the code for those methods.

Public class Book private int numPages Which of the following best explains why the code segment will not compile?

B - Line 4 will not compile because variables of type Book may only call methods in the Book class.

public class Backyard { private int length; private int width; public Backyard(int l, int w) { length = l; width = w; } public int getLength() { return length; } public int getWidth() { return width; } public boolean equals(Object other) { if (other == null) { return false; } Backyard b = (Backyard) object; return (length == b.getLength() && width == b.getWidth()); } } The following code segment appears in a class other than Backyard. It is intended to print true if b1 and b2 have the same lengths and widths, and to print false otherwise. Assume that x, y, j, and k are properly declared and initialized variables of type int. Backyard b1 = new Backyard(x, y); Backyard b2 = new Backyard(j, k); System.out.println( /* missing code */ ); Which of the following can be used as a replacement for /* missing code */ so the code segment works as intended?

B - b1.equals(b2)

A bear is an animal and a zoo contains many animals, including bears. Three classes Animal, Bear, and Zoo are declared to represent animal, bear, and zoo objects. Which of the following is the most appropriate set of declarations?

B - public class Bear extends Animal { ... } public class Zoo { private Animal[] myAnimals; ... }

public class Rectangle { private int height; private int width; public Rectangle() { height = 1; width = 1; } public Rectangle(int x) { height = x; width = x; } public Rectangle(int h, int w) { height = h; width = w; } // There may be methods that are not shown. } public class Square extends Rectangle { public Square(int x) { /* missing code */ } } Which of the following code segments can replace /* missing code */ so that the Square class constructor initializes the Rectangle class instance variablesheight and width to x ?

B - super(x);

public class Book { private String bookTitle; public Book() { bookTitle = ""; } public Book(String title) { bookTitle = title; } } public class TextBook extends Book { private String subject; public TextBook(String theSubject) { subject = theSubject; } } The following code segment appears in a method in a class other than Book or TextBook. Book b = new TextBook("Psychology"); Which of the following best describes the effect of executing the code segment?

C - There is an implicit call to the zero-parameter Book constructor. The instance variable bookTitle is then initialized to "". Then, the instance variable subject is initialized with the value of the parameter theSubject.

public class Computer { private String memory; public Computer() { memory = "RAM"; } public Computer(String m) { memory = m; } public String getMemory() { return memory; } } public class Smartphone extends Computer { private double screenWidth, screenHeight; public SmartPhone(double w, double h) { super("flash"); screenWidth = w; screenHeight = h; } public double getScreenWidth() { return screenWidth; } public double getScreenHeight() { return screenHeight; } } The following code segment appears in a class other than Computer orSmartphone. Computer myPhone = new SmartPhone(2.55, 4.53); System.out.println("Device has memory: " + myPhone.getMemory() + ", screen area: " + myPhone.getScreenWidth() * myPhone.getScreenHeight() + " square inches."); The code segment is intended to produce the following output. Device has memory: flash, screen area: 11.5515 square inches. Which of the following best explains why the code segment does not work as intended?

C - An error occurs during compilation because thegetScreenWidth and getScreenHeight methods are not defined for the Computer object myPhone.

public class A { private int x; public A() { x = 0; } public A(int y) { x = y; } // There may be instance variables, constructors, and methods that are not shown. } public class B extends A { private int y; public B() { /* missing code */ } // There may be instance variables, constructors, and methods that are not shown. } Which of the following can be used to replace /* missing code */ so that the statement B temp = new B(); will construct an object of type B and initialize both x and y with 0 ? y = 0 super (0); y = 0; x = 0; y = 0;

C - I and II only

public class Apple { public void printColor() { System.out.print("Red"); } } public class GrannySmith extends Apple { public void printColor() { System.out.print("Green"); } } public class Jonagold extends Apple { // no methods defined } The following statement appears in a method in another class. someApple.printColor(); Under which of the following conditions will the statement print "Red" ? When someApple is an object of type Apple When someApple is an object of type GrannySmith When someApple is an object of type Jonagold

C - I and III only

public class Road { private String roadName; public Road(String name) { roadName = name; } } public class Highway extends Road { private int speedLimit; public Highway(String name, int limit) { super(name); speedLimit = limit; } } The following code segment appears in a method in another class. Road r1 = new Highway("Interstate 101", 55); // line 1 Road r2 = new Road("Elm Street"); // line 2 Highway r3 = new Road("Sullivan Street"); // line 3 Highway r4 = new Highway("New Jersey Turnpike", 65); // line 4 Which of the following best explains the error, if any, in the code segment?

C - Line 3 will cause an error because a Highway variable cannot be instantiated as an object of type Road.

public class Ticket { private double price; public Ticket(double p) { price = p; } public double getPrice() { return price; } public String toString() { return "Price is " + getPrice(); } } public class DiscountTicket extends Ticket { public DiscountTicket(double p) { super(p); } public double getPrice() { return super.getPrice() / 2.0; } } The following code segment appears in a class other than Ticket orDiscountTicket. Ticket t = new DiscountTicket(10.0); System.out.println(t); What output, if any, is produced when the code segment is executed?

C - Price is 5.0

public class Drink { // implementation not shown } public class Coffee extends Drink { // There may be instance variables and constructors that are not shown. // No methods are defined for this class. } The following code segment appears in a method in a class other than Drink or Coffee. Coffee myCup = new Coffee(); myCup.setSize("large"); Which of the following must be true so that the code segment will compile without error?

C - The Drink class must have a public method named setSize that takes a String value as its parameter.

public class Beverage { private int temperature; public Beverage(int t) { temperature = t; } public int getTemperature() { return temperature; } public boolean equals(Object other) { if (other == null) { return false; } Beverage b = (Beverage) other; return (b.getTemperature() == temperature); } } The following code segment appears in a class other than Beverage. Assume that x and y are properly declared and initialized int variables. Beverage hotChocolate = new Beverage(x); Beverage coffee = new Beverage(y); boolean same = /* missing code */; Which of the following can be used as a replacement for /* missing code */ so that the boolean variable same is set to true if and only if the hotChocolate and coffee objects have the same temperature values?

C - hotChocolate.equals(coffee)

public class ClassOne { public void methodA() { /* implementation not shown */ } public void methodB() { /* implementation not shown */ } } public class ClassTwo { public void methodA() { /* implementation not shown */ } } public class ClassThree extends ClassOne { public void methodB() { /* implementation not shown */ } } The following declarations occur in a method in another class. ClassOne one = new ClassOne(); ClassTwo two = new ClassTwo(); ClassThree three = new ClassThree(); /* missing method call */ Which of the following replacements for /* missing method call */ will cause a compile-time error?

C - two.methodB();

An online site shows information about Books and Authors. What kind of relationship do these two classes have? A. An is-a relationship. The Author class should be a subclass of the Book class. B. An is-a relationship. The Book class should be a subclass of the Author class. C. A has-a relationship. The Book class has an Author attribute.

C. A has-a relationship. The Book class has an Author attribute.

An online store is working on an online ordering system for Books and Movies. For each type of Published Material (books and movies) they need to track the id, title, date published, and price. Which of the following would be the best design? A. Create one class PublishedMaterial with the requested attributes. B. Create classes Book and Movie and each class has the requested attributes. C. Create the class PublishedMaterial and have Book and Movie inherit from it all the listed attributes. D. Create one class BookStore with the requested attributes. E. Create classes for PublishedMaterial, Books, Movies, Title, Price, ID, Authors, DatePublished

C. Create the class PublishedMaterial and have Book and Movie inherit from it all the listed attributes.

Given the following class definitions which of the following would not compile if it was used in place of the missing code in the main method? class Item { private int x; public void setX(int theX) { x = theX; } // ... other methods not shown } public class EnhancedItem extends Item { private int y; public void setY(int theY) { y = theY; } // ... other methods not shown public static void main(String[] args) { EnhancedItem currItem = new EnhancedItem(); // missing code } } A. currItem.setX(3); B. currItem.setY(2); C. currItem.x = 3; D. currItem.y = 2;

C. currItem.x = 3;

Which of the following declarations in Student would correctly override the getFoodmethod in Person? public class Person { private String name = null; public Person(String theName) { name = theName; } public String getFood() { return "Hamburger"; } } public class Student extends Person { private int id; private static int nextId = 0; public Student(String theName) { super(theName); id = nextId; nextId++; } public int getId() {return id;} public void setId (int theId) { this.id = theId; } } A. public void getFood() B. public String getFood(int quantity) C. public String getFood()

C. public String getFood()

public class Thing1 { public void calc(int n) { n *= 3; System.out.print(n); } } public class Thing2 extends Thing1 { public void calc(int n) { n += 2; super.calc(n); System.out.print(n); } } The following code segment appears in a class other than Thing1 or Thing2. Thing1 t = new Thing2(); t.calc(2); What is printed as a result of executing the code segment?

D - 124

public class Hero { private String name; private int power; public Hero(String n, int p) { name = n; power = p; } public void powerUp(int p) { power += p; } public int showPower() { return power; } } public class SuperHero extends Hero { public SuperHero(String n, int p) { super(n, p); } public void powerUp(int p) { super.powerUp(p * 2); } } The following code segment appears in a class other than Hero and SuperHero. Hero j = new SuperHero("JavaHero", 50); j.powerUp(10); System.out.println(j.showPower()); What is printed as a result of executing the code segment?

D - 70

public class Base { public Base() { System.out.print("Base" + " "); } } public class Derived extends Base { public Derived() { System.out.print("Derived" + " "); } } Assume that the following statement appears in another class. Derived d1 = new Derived(); What is printed as a result of executing the statement?

D - Base Derived

public class Data { private int x; public void setX(int n) { x = n; } // ... other methods not shown } public class EnhancedData extends Data { private int y; public void setY(int n) { y = n: } // ... other methods not shown } Assume that the following declaration appears in a client program. EnhancedData item = new EnhancedData(); Which of the following statements would be valid? I. item.y = 16; II. item.setY(16); III. item.setX(25);

D - II and III only

public class C1 { public C1() { /* implementation not shown */ } public void m1() { System.out.print("A"); } public void m2() { System.out.print("B"); } } public class C2 extends C1 { public C2() { /* implementation not shown */ } public void m2() { System.out.print("C"); } } The following code segment appears in a class other than C1 or C2. C1 obj1 = new C2(); obj1.m1(); obj1.m2(); The code segment is intended to produce the output AB. Which of the following best explains why the code segment does not produce the intended output?

D - Method m2 is executed from the subclass instead of the superclass because obj1 is instantiated as a C2 object.

public interface Student public class Athlete public class TennisPlayer extends Athlete implements Student

D - Student d = new Athlete();

Assume that class Vehicle contains the following method. public void setPrice(double price) { /* implementation not shown */ } Also assume that class Car extends Vehicle and contains the following method. public void setPrice(double price) { /* implementation not shown */ } Assume Vehicle v is initialized as follows. Vehicle v = new Car(); v.setPrice(1000.0); Which of the following is true?

D - The code v.setPrice(1000.0); will cause the setPrice method of the Car class to be called.

public class Bike { private int numOfWheels = 2; public int getNumOfWheels() { return numOfWheels; } } public class EBike extends Bike { private int numOfWatts; public EBike(int watts) { numOfWatts = watts; } public int getNumOfWatts() { return numOfWatts; } } The following code segment occurs in a class other than Bike or EBike. Bike b = new EBike(250); System.out.println(b.getNumOfWatts()); System.out.println(b.getNumOfWheels()); Which of the following best explains why the code segment does not compile?

D - The getNumOfWatts method is not found in the Bike class.

public class Book { private String author; private String title; public Book(String the_author, String the_title) { author = the_author; title = the_title; } } public class Textbook extends Book { private String subject; public Textbook(String the_author, String the_title, String the_subject) { /* missing implementation */ } } Which of the following can be used to replace /* missing implementation */ so that the Textbook constructor compiles without error?

D - super(the_author, the_title); subject = the_subject;

What is the output from running the main method in the Shape class? public class Shape { public void what() { System.out.print("Shape ");} public static void main(String[] args) { Shape[] shapes = {new Shape(), new Rectangle(), new Square(), new Circle()}; for (Shape s : shapes) { s.what(); System.out.print(" "); } } } class Rectangle extends Shape { public void what() { System.out.print("Rectangle "); } } class Square extends Rectangle { } class Oval extends Shape { public void what() { System.out.print("Oval "); } } class Circle extends Oval { public void what() { System.out.print("Circle ");} } A. Shape Shape Shape Shape B. Shape Rectangle Square Circle C. There will be a compile time error D. Shape Rectangle Rectangle Circle E. Shape Rectangle Rectangle Oval

D. Shape Rectangle Rectangle Circle

public class Pet { public void speak() { System.out.print("pet sound"); } } public class Dog extends Pet { public void bark() { System.out.print("woof woof"); } public void speak() { bark(); } } public class Cat extends Pet { public void speak() { System.out.print("meow meow"); } } The following statement appears in a method in another class. myPet.speak(); Under which of the following conditions will the statement compile and run without error? When myPet is an object of type Pet When myPet is an object of type Dog When myPet is an object of type Cat

E - I, II, and III

public class Base { private int myVal; public Base() { myVal = 0; } public Base(int x) { myVal = x; } } public class Sub extends Base { public Sub() { super(0); } } Which of the following statements will NOT compile?

E - Sub s3 = new Sub(5);

public class Example0 { public void doNothing(Examplel b, Example2 c) { } } public class Examplel extends Example0 { } public class Example2 extends Examplel { } The following initializations appear in a different class. Example0 e0 = new Example0(); Examplel el = new Examplel(); Example2 e2 = new Example2(); Which of the following is a correct call to doNothing?

E - e2.doNothing(e2, e2);

public class Shoe { private String shoeBrand; private String shoeModel; public Shoe(String brand, String model) { shoeBrand = brand; shoeModel = model; } // No other constructors } public class Boot extends Shoe { private double heelHeight; public Boot(String brand, String model, double height) { /* missing implementation */ } }

E - super(brand, model); heelHeight = height;

public class Artifact { private String title; private int year; public Artifact(String t, int y) { title = t; year = y; } public void printInfo() { System.out.print(title + " (" + year + ")"); } } public class Artwork extends Artifact { private String artist; public Artwork(String t, int y, String a) { super(t, y); artist = a; } public void printInfo() { /* missing implementation */ } } The following code segment appears in a method in another class. Artwork starry = new Artwork("The Starry Night", 1889, "Van Gogh"); starry.printInfo(); The code segment is intended to produce the following output. The Starry Night (1889) by Van Gogh Which of the following can be used to replace /* missing implementation */ in the printInfo method in the Artwork class so that the code segment produces the intended output?

E - super.printInfo(); System.out.print(" by " + artist);


Conjuntos de estudio relacionados

Counseling Theory & Practice Final Exam

View Set

Mg Sulfate, Betamethasone, Indomethacin, Nifedipine, Oxytocin, Terbutaline, Insulin & Heparin

View Set

CHAPTER 1 ECONOMICS - WHAT IS ECONOMICS (True & False/ Multiple Choice)

View Set

Superlative Adjectives cloze sentence fill-ins

View Set

Unit 11: Dynamic Assessment (Diag)

View Set

Chapter 6: Designing a Motivating Work Environment

View Set

Entrepreneurship Test Chapters 3 and 4

View Set