Question

What is the output of the following Java program? public class Food {     static int...

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. sweet

b. 1

c. The program does not compile.

d. 2

e. spicy

Clear my choice

Question 2

Not yet answered

Marked out of 1.00

Flag question

Question text

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. a class method

c. gets executed when the program runs

d. a static method

e. a public method

Clear my choice

Question 3

Not yet answered

Marked out of 1.00

Flag question

Question text

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. the program does not compile

b. no output

c. bland

d. spicy

e. bland
spicy

Clear my choice

Question 4

Not yet answered

Marked out of 1.00

Flag question

Question text

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. bland
spicy

b. the program does not compile

c. bland

d. no output

e. spicy

Clear my choice

Question 5

Not yet answered

Marked out of 1.00

Flag question

Question text

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. the program does not compile

b. bland

c. no output

d. bland
spicy

e. spicy

Clear my choice

Question 6

Not yet answered

Marked out of 1.00

Flag question

Question text

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. spicy

b. false

c. smoky

d. sweet

e. true

Clear my choice

Question 7

Not yet answered

Marked out of 1.00

Flag question

Question text

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

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. A "Clicker" object responds to button clicks.

b. The "Clicker" class can be run as a program.

c. A "Clicker" object can be assigned to an "ActionEvent" variable.

d. A "Clicker" object can be assigned to an "ActionListener" variable.

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

Clear my choice

Question 8

Not yet answered

Marked out of 1.00

Flag question

Question text

What is the output of the following Java program?


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

Select one:

a. bland

b. the program does not compile

c. bland
spicy

d. spicy

e. no output

Clear my choice

Question 9

Not yet answered

Marked out of 1.00

Flag question

Question text

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. 1

c. 2

d. spicy

e. The program does not compile.

Clear my choice

Question 10

Not yet answered

Marked out of 1.00

Flag question

Question text

A subclass will _____ from its superclass.

Select one:

a. inherit

b. extend

c. implement

d. abstract

e. override

Clear my choice

Question 11

Not yet answered

Marked out of 1.00

Flag question

Question text

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. MouseListener

b. JFrame

c. MouseEvent

d. this

e. java.awt.event

Clear my choice

Question 12

Not yet answered

Marked out of 1.00

Flag question

Question text

Which one of the following claims about Java is INCORRECT?

Select one:

a. A constructor's name is its return type.

b. A default constructor is always provided by the compiler.

c. A constructor can only be called with "new".

d. Constructors can be overloaded with different parameter lists.

e. A constructor's name must match the name of the class.

Clear my choice

Question 13

Not yet answered

Marked out of 1.00

Flag question

Question text

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 = new Food("spicy");
        System.out.println(pepper == chile);
    }
}

Select one:

a. true

b. false

c. spicy

d. sweet

e. smoky

Clear my choice

Question 14

Not yet answered

Marked out of 1.00

Flag question

Question text

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. button = new JButton(String.valueOf(count));

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

c. int count;

d. JButton button;

e. public void actionPerformed(ActionEvent e) {

Clear my choice

Question 15

Not yet answered

Marked out of 1.00

Flag question

Question text

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. e

b. button

c. super

d. count

e. this

Clear my choice

Homework Answers

Answer #1

Answer 1:

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());
    }
}

Correct Answer is Option (a) sweet.

Answer 2:

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

Correct Answer is Option (a) a setter method.

Answer 3:

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();
    }
}

Correct Answer is Option (b) No Output.

Answer 4:

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();
    }
}

Correct Answer is Option (b) the program does not compile.

Answer 5:

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();
    }
}

Correct Answer is Option (e) spicy.

Answer 6:

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());
    }
}

Correct Answer is Option (c) smoky.

Answer 7:

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

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(); }
}

Correct answer is Option(d) A "Clicker" object can be assigned to an "ActionListener" variable.

Answer 8:

What is the output of the following Java program?
class Food {
    Food() { System.out.println("bland"); }
    Food(String flavor) { System.out.println(flavor); }
}
class Pepper extends Food {
    Pepper() { super("spicy"); }
}
public class Lunch {
    public static void main(String[] args) {
        Food lunch = new Pepper();
    }
}

Correct answer is option(d) spicy.

Answer 9:

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());
    }
}

Correct answer is Option(d) spicy

Answer 10:

A subclass will inherit from its superclass.

So correct answer is Option(a) inherit

Answer 11:

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(); }
}

Correct Answer is Option(a) MouseListener

Answer 12:

Which one of the following claims about Java is INCORRECT?

Option(a) is incorrect.

So answer is Option(a) A constructor's name is its return type.

Answer 13:

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 = new Food("spicy");
        System.out.println(pepper == chile);
    }

}

Correct Answer is Option(b) false.

Answer 14:

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(); }
}

Correct Answer is Option(d) JButton button;

Answer 15:

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(); }
}

Correct Answer is Option(e) this.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
What is the output of the following Java program? class Food { Food() { System.out.println(flavor); }...
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
What is the output of the following Java program? class Food { String flavor = "bland";...
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. bland b. the program does not compile c. no output d. spicy e. sweet
What is the output of the following Java program? interface Food {     public void printFlavor();...
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. spicy b. no output c. the program does not compile d. bland e. bland spicy
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class...
1) 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());     } } a. a class variable b. a constructor c. a local object variable d....
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*;...
1) Consider the following Java program. Which statement updates the appearance of a button? 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(); } } a. add(button);...
Consider the following Java program : public static void main (string args [ ]) { int...
Consider the following Java program : public static void main (string args [ ]) { int result, x ; x = 1 ; result = 0; while (x < = 10) { if (x%2 == 0) result + = x ; + + x ; } System.out.println(result) ; } } Which of the following will be the output of the above program? A. 35 B. 30 C. 45 D. 35 2. public static void main(String args[]) { int i =...
JAVA -Consider this program: public class Main { public static void main(String[] args) { String s1...
JAVA -Consider this program: public class Main { public static void main(String[] args) { String s1 = new String("hello"); String s2 = "hello"; String s3 = "hello";    System.out.println(s1 == s3); System.out.println(s1.equals(s3)); System.out.println(s2 == s3); } } When we run the program, the output is: false true true Explain why this is the output, using words and/or pictures.
public class Programming { public static void main(String args[]) { System.out.println("I am learning how to program.");...
public class Programming { public static void main(String args[]) { System.out.println("I am learning how to program."); } } Compile this and execute this program then modify it to display I am learning how to program in Java. Change class name to Javaprogramming.java. compile and execute. Modify the Javaprogramming class so it prints two lines of output. Change name to Awesome. Add second output statement that displays That's awesome ! Save as awesome.java then compile and execute
//What is the output? import java.util.HashMap; public class AirportCodes {    public static void main (String[]...
//What is the output? import java.util.HashMap; public class AirportCodes {    public static void main (String[] args) {       HashMap<String, String> airportCode = new HashMap<String, String>();       airportCode.put("GRX", "Granada, Spain");       airportCode.put("ALB", "Albany, USA");       airportCode.put("IWJ", "Iwami, Japan");       System.out.print("ALB: ");       System.out.println(airportCode.get("ALB"));       airportCode.put("IWJ", "Ivalo, Finland");       System.out.print("IWJ: ");       System.out.println(airportCode.get("IWJ"));    } }
Fix the program: what if the input is three? import java.util.Scanner public class Test { public...
Fix the program: what if the input is three? import java.util.Scanner public class Test { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter an integer: "); int m = in.nextInt(); System.out.print("Enter another integer: "); int n = in.nextInt(); System.out.println(m + " " + n); } }