You are on page 1of 33

Raymond Enokela

Home  My courses  CS 1102 - AY2021-T2  26 November - 2 December  Graded Quiz Unit 3

Started on Tuesday, 1 December 2020, 3:12 PM


State Finished
Completed on Tuesday, 1 December 2020, 3:52 PM
Time taken 40 mins 14 secs
Marks 14.00/20.00
Grade 70.00 out of 100.00

Question 1 Correct Mark 1.00 out of 1.00

In a for loop, how many times does the continuation condition run?

Select one:

a. Exactly once.

b. At least once, at the end of each iteration.

c. Zero or more times, at the beginning of each iteration.

d. Zero or more times, at the end of each iteration.

e. At least once, at the beginning of each iteration.

Your answer is correct.

See Section 3.4.1 of Eck (2014).

The correct answer is: At least once, at the beginning of each iteration.


Question 2 Correct Mark 1.00 out of 1.00

Consider the following block of Java code. How many times will it output "Hello"?
for (int i = 1; i < 10; i--)
{
    System.out.println("Hello");
}

Select one:

a. 0

b. 9

c. 1

d. 10

e. Way too many!

Your answer is correct.

Notice the update, "i--". "i" starts less than 10 and just keeps getting smaller. (The loop is technically not
in nite. "i" will eventually reach the most-negative value that "int" can represent, and then it will wrap
around to the largest possible "int", ending the loop.) See Section 3.4.1 of Eck (2014).

The correct answers are: 1, Way too many!

Question 3 Correct Mark 1.00 out of 1.00

Each of the individual tasks that a CPU is working on is called:

Select one:

a. a thread

b. a program counter

c. an object

d. a message

e. an address

Your answer is correct.

See Section 1.2 of Eck (2014).

The correct answer is: a thread


Question 4 Correct Mark 1.00 out of 1.00

Consider the following class de nition. Which variables can be used in the missing "println"
expression on line 20?
public class PrintStu
2  {
3      public static void main()
4      {
6          {
7              int i = -1;
8              System.out.println(_____);
9          }
10         int j = 1;
11         for (j = 0; j < 10; j++) {
12             System.out.println(_____);
13         }
14         {
15             int k;
16             for (k = 0; k < 10; k++) {
17                System.out.println(_____);
18             }
19         }
20        System.out.println(_____);
21     }
22 }

Select one:

a. Only "k"

b. "j" and "k"

c. Only "j"

d. "i" and "j"

e. Only "i"

Your answer is correct.

"i" and "k" are no longer in scope. Only "j" is still in scope. See Section 3.1.1 of Eck (2014).

The correct answer is: Only "j"


Question 5 Correct Mark 1.00 out of 1.00

Consider the following Java declaration and assignment statement.


float x = y;
Which one of the following types is "y" NOT allowed to be?

Select one:

a. short

b. oat

c. double

d. int

e. long

Your answer is correct.

Java automatically converts values from short, int, and long to oat. It does not automatically convert
double to oat. See Section 2.5.6 of Eck (2014).

The correct answer is: double


Question 6 Correct Mark 1.00 out of 1.00

What is the output of the following Java program?

class Sum {
    static int sum = 0;
    static void add(int i) { i++; }
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) add(sum);
        System.out.println(sum);
    }
}

Select one:

a. 10

b. 9

c. 45

d. 0

e. 100

Your answer is correct.

The "add" method increments the parameter "i", which is a copy of the argument "sum". The value of "sum"
never changes. See Section 4.3.2 of Eck (2014).

The correct answer is: 0

Question 7 Correct Mark 1.00 out of 1.00

Which of the following keywords is useful for loops that should always execute at least once?

Select one:

a. switch

b. break

c. continue

d. do

e. while

Your answer is correct.

See Section 3.3.2 of Eck (2014).

The correct answer is: do



Question 8 Correct Mark 1.00 out of 1.00

 Consider the following Java program:

1 public class HelloWorld {


2     // My first program!
3     public static void main(String[] args) {
4         System.out.println("Hello, World!");
5     }
6 }

What starts on line 4?

Select one:

a. a class de nition

b. a method (subroutine) de nition

c. a comment

d. a variable declaration

e. a statement

Your answer is correct.

See Section 2.1 of Eck (2014).

The correct answers are: a statement, a class de nition

Question 9 Incorrect Mark 0.00 out of 1.00

Assume "test" is a boolean variable. Which of the following expressions is equivalent to "test ==
false"?

Select one:

a. test = true

b. test

c. test.equals(true)

d. !test

Your answer is incorrect.

See Section 3.3.2 of Eck (2014).

The correct answer is: !test


Question 10 Correct Mark 1.00 out of 1.00

Consider the following line of Java code.


System.out.println("Hello, World!");
"println" is which of the following?

Select one:

a. a class

b. a method (subroutine)

c. an object

d. a parameter

e. a statement

Your answer is correct.

"println" is a method of the object "out". See Section 2.3.2 of Eck (2014).

The correct answer is: a method (subroutine)

Question 11 Correct Mark 1.00 out of 1.00

Which of the following types is NOT a primitive type?

Select one:

a. String

b. short

c. double

d. boolean

e. char

Your answer is correct.

The correct answer is: String


Question 12 Incorrect Mark 0.00 out of 1.00

Assume that the variables "x" and "y" both have type "int". Which one of the following is NOT a
boolean expression?

Select one:

a. x = y

b. x >= y

c. ((x > 0) && (y > 0))

d. (x > 0) ? (x > y) : (x < y)

Your answer is incorrect.

"x = y" is an int assignment statement. The other choices are all legal boolean expressions. See Sections
2.5.4 and 2.5.6 of Eck (2014).

The correct answer is: x = y

Question 13 Incorrect Mark 0.00 out of 1.00

Which of the following keywords is useful for skipping to the next iteration of a loop?

Select one:

a. break

b. do

c. continue

d. while

e. switch

Your answer is incorrect.

See Section 3.3.3 of Eck (2014).

The correct answer is: continue


Question 14 Incorrect Mark 0.00 out of 1.00

What is output by the following Java program?

class Compute {
    static int compute() { return 42; }
    static int compute(int i) { return i+1; }
    public static void main(String[] args) {
        System.out.println(compute(compute(0)));
    }
}

Select one:

a. 0

b. 42

c. 1

d. 2

e. 43

Your answer is incorrect.

The inner call to "compute" has an argument, so it uses the second method de nition, which returns 0+1, or
1. This 1 becomes the argument to the outer call, which then returns 1+1, or 2. The rst de nition of
"compute" is never used. See Section 4.3.3 of Eck (2014).

The correct answer is: 2

Question 15 Incorrect Mark 0.00 out of 1.00

Which one of the following lines of Java code does NOT include a method call?

Select one:

a. int x = compute(y);

b. if (i < 1) { compute(); }

c. compute(x,y,z);

d. compute();

e. void compute() {}

Your answer is incorrect.

Answer is a method de nition, not a method call. See Sections 4.2.1 and 4.2.2 of Eck (2014).

The correct answer is: void compute() {}



Question 16 Correct Mark 1.00 out of 1.00

1. Consider the following class de nition. Which variables can be used in the missing "println"
expression on line 12?
1  public class PrintStu
2  {
3      public static void main()
4      {
6          {
7              int i = -1;
8              System.out.println(_____);
9          }
10         int j = 1;
11         for (j = 0; j < 10; j++) {
12             System.out.println(_____);
13         }
14         {
15             int k;
16             for (k = 0; k < 10; k++) {
17                System.out.println(_____);
18             }
19         }
20        System.out.println(_____);
21     }
22 }

Select one:

a. "j" and "k"

b. Only "k"

c. Only "j"

d.
1. Only "i"

e. "i" and "j"

Your answer is correct.

"i" is no longer in scope. "k" has not been declared yet. See Section 3.1.1 of Eck (2014).

The correct answer is: Only "j"


Question 17 Correct Mark 1.00 out of 1.00

In a for loop, how many times does the update run?

Select one:

a. Zero or more times, at the end of each iteration.

b. At least once, at the beginning of each iteration.

c. Exactly once.

d. At least once, at the end of each iteration.

e. Zero or more times, at the beginning of each iteration.

Your answer is correct.

See Section 3.4.1 of Eck (2014).

The correct answer is: Zero or more times, at the end of each iteration.

Question 18 Correct Mark 1.00 out of 1.00

Which of the following can a class NOT be used for?

Select one:

a. a container for static methods (subroutines)

b. a container for static variables

c. a primitive type

d. a type for method parameters

e. a type for variables

Your answer is correct.

Primitive types are not classes. See Section 2.3 of Eck (2014).

The correct answer is: a primitive type


Question 19 Incorrect Mark 0.00 out of 1.00

Consider the following line of Java code.


System.out.println("Hello, World!");
"out" is which of the following?

Select one:

a. a method (subroutine)

b. an object

c. a parameter

d. a class

e. a statement

Your answer is incorrect.

"out" is a static member object of the class "System". See Section 2.3.2 of Eck (2014).

The correct answer is: an object

Question 20 Correct Mark 1.00 out of 1.00

Which one of the following is used in Java programming to handle asynchronous events?

Select one:

a. pragmatics

b. event handlers

c. reserved words

d. short circuits

e. protocols

Your answer is correct.

The correct answer is: event handlers

← Self-Quiz Unit 3

Jump to...

Unit 2 Programming Assignment Solution →


Raymond Enokela

Home  My courses  CS 1102 - AY2021-T2  17 December - 23 December  Graded Quiz Unit 6

Started on Wednesday, 23 December 2020, 5:08 PM


State Finished
Completed on Wednesday, 23 December 2020, 6:08 PM
Time taken 1 hour
Marks 15.00/20.00
Grade 75.00 out of 100.00
Question 1 Correct Mark 1.00 out of 1.00

Consider the following Java program. Which one of the following does NOT describe
"MouseWhisperer"?

import java.awt.event.*;
import javax.swing.*;
public class MouseWhisperer extends JFrame implements MouseListener {
    MouseWhisperer() {
        super("COME CLOSER");
        setSize(300,100);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        addMouseListener(this);
        setVisible(true);
    }
    public void mouseClicked(MouseEvent e) { setTitle("OUCH"); }
    public void mousePressed(MouseEvent e) { setTitle("LET GO"); }
    public void mouseReleased(MouseEvent e) { setTitle("WHEW"); }
    public void mouseEntered(MouseEvent e) { setTitle("I SEE YOU"); }
    public void mouseExited(MouseEvent e) { setTitle("COME CLOSER"); }
    public static void main(String[] args) { new MouseWhisperer(); }
}

Select one:

a. A "MouseWhisperer" object responds to mouse movement.

b. A "MouseWhisperer" object responds to mouse clicks.

c. The "MouseWhisperer" class can be run as a program.

d. A "MouseWhisperer" object listens for action events.

e. A "MouseWhisperer" object can be assigned to a "JFrame" variable.

Your answer is correct.

A "MouseWhisperer" object responds to mouse events ("addMouseListener"), not action events. See
Sections 6.1.3 and 6.3.1.

The correct answer is: A "MouseWhisperer" object listens for action events.
Question 2 Correct Mark 1.00 out of 1.00

Consider the following Java program, which one of the following best describes " avor"?

public class Food {


    static int count;
    private String flavor = "sweet";
    Food() { count++; }
    void setFlavor(String s) { flavor = s; }
    String getFlavor() { return flavor; }
    static public void main(String[] args) {
        Food pepper = new Food();
        System.out.println(pepper.getFlavor());
    }
}

Select one:

a. a local object variable

b. a constructor

c. a method

d. an instance variable

e. a class variable

Your answer is correct.

See Section 5.1.1 of Eck (2014).

The correct answer is: an instance variable


Question 3 Incorrect Mark 0.00 out of 1.00

What is the output of the following Java program?

class Food {
    Food() { System.out.println(flavor); }
    String flavor = "bland";
}
class Pepper extends Food {
    String flavor = "spicy";
}
public class Lunch {
    public static void main(String[] args) {
        Food lunch = new Pepper();
    }
}

Select one:

a. spicy

b. the program does not compile

c. bland
spicy

d. no output

e. bland

Your answer is incorrect.

Unlike methods, constructors are NOT polymorphic. The compiler automatically calls the "Food"
constructor, which uses the " avor" member for class "Food", not the one for the subclass "Pepper". See
Sections 5.6.2 and 5.6.3.

The correct answer is: bland


Question 4 Correct Mark 1.00 out of 1.00

Consider the following Java program. Which object receives events?

import java.awt.event.*;
import javax.swing.*;
public class MouseWhisperer extends JFrame implements MouseListener {
    MouseWhisperer() {
        super("COME CLOSER");
        setSize(300,100);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        addMouseListener(this);
        setVisible(true);
    }
    public void mouseClicked(MouseEvent e) { setTitle("OUCH"); }
    public void mousePressed(MouseEvent e) { setTitle("LET GO"); }
    public void mouseReleased(MouseEvent e) { setTitle("WHEW"); }
    public void mouseEntered(MouseEvent e) { setTitle("I SEE YOU"); }
    public void mouseExited(MouseEvent e) { setTitle("COME CLOSER"); }
    public static void main(String[] args) { new MouseWhisperer(); }
}

Select one:

a. this

b. java.awt.event

c. MouseListener

d. JFrame

e. MouseEvent

Your answer is correct.

"this" is registered as a listener by the "addMouseListener" call. (Also, "this" is the only choice that is an
object. The other choices are packages, classes, or interfaces.) See Section 6.3.1.

The correct answer is: this


Question 5 Correct Mark 1.00 out of 1.00

Consider the following Java program. Which line implements an interface method?

import java.awt.event.*;
import javax.swing.*;
public class MouseWhisperer extends JFrame implements MouseListener {
    MouseWhisperer() {
        super("COME CLOSER");
        setSize(300,100);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        addMouseListener(this);
        setVisible(true);
    }
    public void mouseClicked(MouseEvent e) { setTitle("OUCH"); }
    public void mousePressed(MouseEvent e) { setTitle("LET GO"); }
    public void mouseReleased(MouseEvent e) { setTitle("WHEW"); }
    public void mouseEntered(MouseEvent e) { setTitle("I SEE YOU"); }
    public void mouseExited(MouseEvent e) { setTitle("COME CLOSER"); }
    public static void main(String[] args) { new MouseWhisperer(); }
}

Select one:

a. addMouseListener(this);

b. super("COME CLOSER");

c. public class MouseWhisperer extends JFrame implements MouseListener {

d. public void mouseEntered(MouseEvent e) { setTitle("I SEE YOU"); }

e. public static void main(String[] args) { new MouseWhisperer(); }

Your answer is correct.

See Section 6.3.2.

The correct answer is: public void mouseEntered(MouseEvent e) { setTitle("I SEE YOU"); }
Question 6 Correct Mark 1.00 out of 1.00

What is the output of the following Java program?

class Food {
    String flavor = "bland";
    void printFlavor() { System.out.println(flavor); }
}
class Pepper extends Food {
    String flavor = "spicy";
}
public class Lunch {
    public static void main(String[] args) {
        Food lunch = new Pepper();
        lunch.printFlavor();
    }
}

Select one:

a. bland
spicy

b. spicy

c. the program does not compile

d. no output

e. bland

Your answer is correct.

The "Pepper" class inherits the "printFlavor" method but does not override it. Because member variables
are NOT polymorphic, the "printFlavor" method de ned in "Food" sees the member variable " avor" in
"Food", not the one in "Pepper". See Sections 5.6.1 and 5.6.2.

The correct answer is: bland


Question 7 Correct Mark 1.00 out of 1.00

Consider the following Java program, which one of the following best describes "setFlavor"?

public class Food {


    static int count;
    private String flavor = "sweet";
    Food() { count++; }
    void setFlavor(String s) { flavor = s; }
    String getFlavor() { return flavor; }
    static public void main(String[] args) {
        Food pepper = new Food();
        System.out.println(pepper.getFlavor());
    }
}

Select one:

a. a setter method

b. gets executed when the program runs

c. a class method

d. a static method

e. a public method

Your answer is correct.

See Section 5.1.3 of Eck (2014).

The correct answer is: a setter method


Question 8 Correct Mark 1.00 out of 1.00

Consider the following Java program, which one of the following best describes "main"?

public class Food {


    static int count;
    private String flavor = "sweet";
    Food() { count++; }
    void setFlavor(String s) { flavor = s; }
    String getFlavor() { return flavor; }
    static public void main(String[] args) {
        Food pepper = new Food();
        System.out.println(pepper.getFlavor());
    }
}

Select one:

a. a public method

b. a class method

c. gets executed when the program runs

d. a setter method

e. a static method

Your answer is correct.

The correct answer is: gets executed when the program runs
Question 9 Incorrect Mark 0.00 out of 1.00

Consider the following Java program. Which object registers event listeners?

import java.awt.event.*;
import javax.swing.*;
public class Clicker extends JFrame implements ActionListener {
    int count;
    JButton button;
    Clicker() {
        super("Click Me");
        button = new JButton(String.valueOf(count));
        add(button);
        button.addActionListener(this);
        setSize(200,100);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }
    public void actionPerformed(ActionEvent e) {
        count++;
        button.setText(String.valueOf(count));
    }
    public static void main(String[] args) { new Clicker(); }
}

Select one:

a. button

b. super

c. count

d. e

e. this

Your answer is incorrect.

The "button" object registers "this" as an event listener in the call "addActionListener". See Section 6.1.3.

The correct answers are: button, e


Question 10 Correct Mark 1.00 out of 1.00

What is the output of the following Java program?

interface Food {
    public void printFlavor();
}
class Pepper implements Food {
    public void printFlavor() { System.out.println("spicy"); }
}
public class Lunch {
    public static void main(String[] args) {
        Food pepper = new Pepper();
        pepper.printFlavor();
    }
}

Select one:

a. no output

b. bland
spicy

c. bland

d. the program does not compile

e. spicy

Your answer is correct.

The "Pepper" class implements the "Food" interface. In particular, it de nes the "printFlavor" method, which
prints "spicy". See Section 5.7.1.

The correct answer is: spicy


Question 11 Correct Mark 1.00 out of 1.00

Consider the following Java program. Which line declares an instance object variable?

import java.awt.event.*;
import javax.swing.*;
public class Clicker extends JFrame implements ActionListener {
    int count;
    JButton button;
    Clicker() {
        super("Click Me");
        button = new JButton(String.valueOf(count));
        add(button);
        button.addActionListener(this);
        setSize(200,100);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }
    public void actionPerformed(ActionEvent e) {
        count++;
        button.setText(String.valueOf(count));
    }
    public static void main(String[] args) { new Clicker(); }
}

Select one:

a. int count;

b. public static void main(String[] args) { new Clicker(); }

c. public void actionPerformed(ActionEvent e) {

d. button = new JButton(String.valueOf(count));

e. JButton button;

Your answer is correct.

"int count;" also declares an instance variable, but it is a primitive type, not an object. See Sections 2.2.2 and
5.1.2.

The correct answer is: JButton button;


Question 12 Incorrect Mark 0.00 out of 1.00

A subclass method can _____ a superclass method with the same name and parameter types.

Select one:

a. implement

b. abstract

c. inherit

d. override

e. extend

Your answer is incorrect.

See Section 5.6.2.

The correct answer is: override


Question 13 Correct Mark 1.00 out of 1.00

What is the output of the following Java program?

abstract class Food {


    void printFlavor() {}
}
class Pepper extends Food {}
public class Lunch {
    public static void main(String[] args) {
        Food lunch = new Pepper();
        lunch.printFlavor();
    }
}

Select one:

a. bland

b. the program does not compile

c. spicy

d. no output

e. bland
spicy

Your answer is correct.

The "Pepper" class inherits the "printFlavor" method from the abstract "Food" class. Abstract classes are
allowed to de ne concrete methods, and "Food" does de ne "printFlavor", though it de nes it to do
nothing: "{}". See Section 5.5.5.

The correct answer is: no output


Question 14 Correct Mark 1.00 out of 1.00

What is the output of the following Java program?

public class Food {


    static int count;
    private String flavor = "sweet";
    Food() { count++; }
    void setFlavor(String s) { s = flavor; }
    String getFlavor() { return flavor; }
    static public void main(String[] args) {
        Food pepper = new Food();
        pepper.setFlavor("spicy");
        System.out.println(pepper.getFlavor());
    }
}

Select one:

a. 2

b. sweet

c. spicy

d. 1

e. The program does not compile.

Your answer is correct.

This program has a sneaky bug. Notice that the so-called setter "setFlavor" sets its formal parameter "s" to
the instance variable " avor" instead of the other way around. The value of " avor" does not change from
its initial value of "sweet". See Section 5.1.3 of Eck (2014). 

The correct answer is: sweet


Question 15 Correct Mark 1.00 out of 1.00

What is the output of the following Java program?

public class Food {


    static int count;
    private String flavor = "sweet";
    Food(String s) { flavor = s; }
    void setFlavor(String s) { flavor = s; }
    String getFlavor() { return flavor; }
    static public void main(String[] args) {
        Food pepper = new Food("spicy");
        System.out.println(pepper.getFlavor());
    }
}

Select one:

a. sweet

b. The program does not compile.

c. 1

d. spicy

e. 2

Your answer is correct.

See Sections 5.1.3 and 5.2.2 of Eck (2014).

The correct answer is: spicy


Question 16 Correct Mark 1.00 out of 1.00

What is the output of the following Java program?


public class Food {
    static int count;
    private String flavor = "sweet";
    Food(String s) { flavor = s; }
    void setFlavor(String s) { flavor = s; }
    String getFlavor() { return flavor; }
    static public void main(String[] args) {
        Food pepper = new Food("spicy");
        Food chile = pepper;
        pepper.setFlavor("smoky");
        System.out.println(chile.getFlavor());
    }
}

Select one:

a. smoky

b. sweet

c. false

d. spicy

e. true

Your answer is correct.

Setting "chile = pepper" causes the two object variables to refer to the same single object. Because "chile"
and "pepper" refer to the same object, the avor set by "pepper.setFlavor" is seen by "chile.getFlavor". See
Section 5.1.2 of Eck (2014).

The correct answer is: smoky


Question 17 Correct Mark 1.00 out of 1.00

A subclass will _____ from its superclass.

Select one:

a. override

b. inherit

c. implement

d. abstract

e. extend

Your answer is correct.

See Section 5.5.2.

The correct answer is: inherit


Question 18 Correct Mark 1.00 out of 1.00

What is the output of the following Java program?

class Food { String flavor = "bland"; }


class Pepper extends Food {
    String flavor = "spicy";
    Pepper(String flavor) { this.flavor = flavor; }
}
public class Lunch {
    public static void main(String[] args) {
        Pepper pepper = new Pepper("sweet");
        System.out.println(pepper.flavor);
    }
}

Select one:

a. the program does not compile

b. bland

c. sweet

d. no output

e. spicy

Your answer is correct.

The "Pepper" constructor uses "this" to set the " avor" member variable to the " avor" parameter. See
Section 5.6.1.

The correct answers are: sweet, the program does not compile
Question 19 Incorrect Mark 0.00 out of 1.00

Consider the following Java program. Which statement sets the title of a window?

import java.awt.event.*;
import javax.swing.*;
public class Clicker extends JFrame implements ActionListener {
    int count;
    JButton button;
    Clicker() {
        super("Click Me");
        button = new JButton(String.valueOf(count));
        add(button);
        button.addActionListener(this);
        setSize(200,100);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }
    public void actionPerformed(ActionEvent e) {
        count++;
        button.setText(String.valueOf(count));
    }
    public static void main(String[] args) { new Clicker(); }
}

Select one:

a. setVisible(true);

b. button.addActionListener(this);

c. super("Click Me");

d. add(button);

e. button.setText(String.valueOf(count));

Your answer is incorrect.

The "JFrame" constructor takes the window name as a parameter, and "JFrame" is the superclass of
"Clicker". See Section 6.1.1.

The correct answer is: super("Click Me");


Question 20 Incorrect Mark 0.00 out of 1.00

What is the output of the following Java program?

class Food {
    void flavor() { System.out.println("bland"); }
}
class Pepper extends Food {
    void flavor() { System.out.println("spicy"); }
}
public class Lunch {
    public static void main(String[] args) {
        Pepper lunch = new Food();
        lunch.flavor();
    }
}

Select one:

a. spicy

b. no output

c. bland
spicy

d. bland

e. the program does not compile

Your answer is incorrect.

The program tries to initialize "lunch", a variable of type "Pepper", with an object of type "Food". A
superclass variable can be initialized to a subclass object, but not the other way around. See Section 5.5.3.

The correct answer is: the program does not compile

← Self-Quiz Unit 6

Jump to...

Unit 5 Programming Assignment Solution →

You might also like