CS 151 Day 12

Cover page image

Cay S. Horstmann

Day 12 Clicker Question 1

Consider the java.awt.Rectangle class and this subclass:

public class Square extends Rectangle
{
   public Square(int x, int y, int width)
   {
      super(x, y, width, width);
   }
}

What is true about this class?

  1. The constructor has a syntax error.
  2. The class doesn't compile because it has no instance fields or methods.
  3. It violates the law of Demeter.
  4. It violates the Liskov substitution principle.

Day 12 Clicker Question 2

What does the call

car.translate(x, y);

do in section 6.2 of the textbook?

  1. It moves the car when the mouse moves
  2. It moves the car to position (x, y)
  3. It moves the car by x horizontally and y vertically
  4. It translates the user manual to a foreign language

Day 12 Clicker Question 3

It is often said that inheritance is overrated. For polymorphism, interfaces often suffice. Which of the following design patterns require the use of inheritance? Check all that apply, or leave all unchecked if inheritance isn't required for any.

  1. Strategy
  2. Decorator
  3. Composite
  4. Template Method

Lab

lab

Do problem 6.17 from your text book with a buddy.

Discussion

discussion