Question
Question 21 Which one of the following is used in Java programming to handle asynchronous events? Select one: a. constructors b. event handlers c. overloading
Question 21
Which one of the following is used in Java programming to handle asynchronous events?
Select one:
a. constructors
b. event handlers
c. overloading
d. pragmatics
e. protocols
Question 22
Consider the following Java program.
1 public class HelloWorld {
2// My first program!
3public static void main(String[] args) {
4System.out.println("Hello, World!");
5}
6 }
What starts on line 1?
Select one:
a. a statement
b. a package
c. a method definition
d. a comment
e. a class definition
Question 23
Which of the following keywords is useful for skipping to the next iteration of a loop?
Select one:
a. break
b. case
c. continue
d. extends
e. switch
Question 24
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. bland
b. bland
spicy
c. (no output)
d. spicy
e. the program does not compile
bland
Question 25
A subclass will ___ from its superclasses.
Select one:
a. extend
b. implement
c. inherit
d. overload
e. override
Question 26
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. public class MouseWhisperer extends JFrame implements MouseListener {
c. public static void main(String[] args) { new MouseWhisperer(); }
d. public void mouseEntered(MouseEvent e) { setTitle("I SEE YOU"); }
e. setVisible(true);
Question 27
Which one of the following does NOT describe an array?
Select one:
a. Its elements can be a primitive type.
b. The number of its elements can change.
c. It can be used in a for-each loop.
d. It has a numbered sequence of elements.
e. It provides efficient random access to its elements.
Question 28
Consider the following Java program.
1 public class HelloWorld {
2// My first program!
3public static void main(String[] args) {
4System.out.println("Hello, World!");
5}
6 }
What starts on line 3?
Select one:
a. a statement
b. a package
c. a method definition
d. a comment
e. a class definition
Question 29
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. false
b. smoky
c. spicy
d. sweet
e. true
Question 30
Which of the following can a class NOT be used for?
Select one:
a. a primitive type
b. a container for static methods
c. a container for static variables
d. a type for method parameters
e. a type for variables
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started