Professional Documents
Culture Documents
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
method in the Shirt class? Mark for Review
(1) Points
getShirtSize() (*)
price
size
color
Correct
3. You design a Circle class with various fields and methods. Which of the following could
be fields in this class? Distinguish which of these are between the properties and Mark for Review
behavior. (1) Points
radius (*)
calculateDiameter()
color (*)
calculateArea()
calculateCircumference()
Correct
4. Code within curly braces is called a “Block of code”.
Mark for Review
(1) Points
True (*)
False
Correct
True (*)
False
Correct
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
again removes the breakpoint. Mark for Review
(1) Points
True (*)
False
Correct
7. Which of the following are adequate definitions for components of the Spiral Model of
Development? Mark for Review
(1) Points
Correct
8. The Spiral Model reflects an iterative development process.
Mark for Review
(1) Points
True (*)
False
Correct
9. A software feature may allow the user to perform a specific task.
Mark for Review
(1) Points
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
data type. Mark for Review
(1) Points
True (*)
False
Correct
Section 3
(Answer all questions in this section)
12. What is parsing?
Mark for Review
(1) Points
Correct
8
9 (*)
34
7
Correct
const
final (*)
static
break
Correct
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
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
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
variables. Mark for Review
(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 library are organized into packages.
Mark for Review
(1) Points
True (*)
False
Correct
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 the javax.swing package. Which two will
import those classes? Mark for Review
(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
Section 4
(Answer all questions in this section)
True
False (*)
Correct
JavA World!
JAvA World! (*)
Java World!
JAva World!
Correct
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 together
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
information on the accountholder’s name, balance, and interest rate. The best Mark for Review
approach is store 30000 separate variables in the main method. (1) Points
True
False (*)
Correct
True (*)
False
Correct
Section 4
(Answer all questions in this section)
Correct
37. You need to generate random integer values in the range 2 through 10. This code
fragment will produce the desired result. Mark for Review
(1) Points
Random r = new Random();
r.nextInt(9) + 2;
True (*)
False
Correct
38. You need to generate random integer values between 0 and 80 (inclusive). Which
statement should you use? Mark for Review
(1) Points
nextInt(81); (*)
nextInt(80);
nextInt();
nextInt(0-79);
Correct
Random (*)
Number
Integer
Double
Correct
40. The Math class methods can be called without creating an instance of a Math object.
Mark for Review
(1) Points
True (*)
False
Correct
Section 4
(Answer all questions in this section)
Section 5
(Answer all questions in this section)
42. A String comparison with == compares the Strings’ locations in memory and not the
content of the String. Mark for Review
(1) Points
True (*)
False
Correct
False
JavaProgramming
Java Programming
True (*)
Correct
Correct
Correct
Section 5
(Answer all questions in this section)
Correct
47. A customer is eligible for a discount based on certain criteria. Under what conditions
does “You qualify for a discount” print? (Hint: There may be more than one correct Mark for Review
answer) (1) Points
int purchase;
int rewardPoints;
if (purchase >= 2000 || rewardPoints >= 4000) {
System.out.println("You qualify for discount");
}
Correct
!
||
% (*)
+ (*)
&&
Correct
Correct
Correct