Java Middle Exam Answers
Java Middle Exam Answers
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 2
(Answer all questions in this section)
name
displaySalary() (*)
salary
empId
Correct
2. There are several fields and methods in a Shirt class. Which of the following could be a
Mark for Review
method in the Shirt class?
(1) Points
getShirtSize() (*)
price
size
color
Correct
3. You design a Circle class with various fields and methods. Which of the following could
Mark for Review
be fields in this class? Distinguish which of these are between the properties and
behavior. (1) Points
radius (*)
calculateDiameter()
color (*)
calculateArea()
calculateCircumference()
Correct
True (*)
False
Correct
True (*)
False
Correct
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 2
(Answer all questions in this section)
6. A breakpoint can be set by clicking a number in the left margin of the IDE. Clicking
Mark for Review
again removes the breakpoint.
(1) Points
True (*)
False
Correct
7. Which of the following are adequate definitions for components of the Spiral Model of
Mark for Review
Development?
(1) Points
Correct
True (*)
False
Correct
True (*)
False
Correct
Section 3
(Answer all questions in this section)
10. The Java compiler automatically promotes byte, short, and chars data type values to int
Mark for Review
data type.
(1) Points
True (*)
False
Correct
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 3
(Answer all questions in this section)
Correct
Correct
8
9 (*)
34
7
Correct
const
final (*)
static
break
Correct
15. What is the output? public static void main(String args[]) {
Mark for Review
int x = 100;
int y = x; (1) Points
y++;
System.out.println("Value of x is " + x);
System.out.println("Value of y is " + y);
}
Value of x is 0
Value of y is 1
Value of x is 100
Value of y is 1
Value of x is 100
Value of y is 1
Value of x is 100
Value of y is 101 (*)
Correct
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 3
(Answer all questions in this section)
16. In Java, char is a primitive data type, while String is an object data type.
Mark for Review
(1) Points
True (*)
False
Correct
True
False (*)
Correct
18. The print() method prints to the console and automatically creates a line.
Mark for Review
(1) Points
True
False (*)
Correct
// Fragment 2
int input = Integer.parseInt(JOptionPane.showInputDialog("??")) + 1;
True (*)
False
Correct
20. Which two statements are true about the Scanner class?
Mark for Review
(1) Points
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 3
(Answer all questions in this section)
21. The Scanner class considers space as the default delimiter while reading the input.
Mark for Review
(1) Points
True (*)
False
Correct
Hello
Hello World
World (*)
Hello
World
Correct
23. Java is a strongly typed language; therefore you must declare a data type for all
Mark for Review
variables.
(1) Points
True (*)
False
Correct
int
Welcome
a (*)
2
Correct
Section 4
(Answer all questions in this section)
25. The classes of the Java class li brary are organized into packages.
Mark for Review
(1) Points
True (*)
False
Correct
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 4
(Answer all questions in this section)
26. Which two are valid import statements of the Scanner class?
Mark for Review
(1) Points
import java.util;
import java.*;
import java.util.*; (*)
import java.util.Scanner; (*)
Correct
True (*)
False
Correct
28. The JFrame and JOptionPane classes are in th e javax.swing package. Which two will
Mark for Review
import those classes?
(1) Points
Correct
29. The indexOf() method returns the index value of a character in the string.
Mark for Review
(1) Points
True (*)
False
Correct
rld! (*)
ld!
orld!
rld
Correct
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 4
(Answer all questions in this section)
True
False (*)
Correct
JavA World!
JAvA World! (*)
Java World!
JAva World!
Correct
33. Which of the following scenarios would be ideal for writing a method?
Mark for Review
(1) Points
When you don’t find similar lines of code to describe an object’s behavior.
For every five to six lines of code.
To group similar data types t ogether
When you don’t want to repeat similar lines of code to describe an object’s
behavior. (*)
Correct
34. You’re designing banking software and need to store 10000 customer accounts with
Mark for Review
information on the accountholder’s name, balance, and interest rate. The best
approach is store 30000 separate variables in the main method. (1) Points
True
False (*)
Correct