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
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.
Get Answers For Free
Most questions answered within 1 hours.