Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 2
(Answer all questions in this section)
1. In the code example below, identify any methods: Mark for Review
public class Employee { (1) Points
public String name = " Duke";
public int empId = 12105;
public float salary;
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
4. Code within curly braces is called a “Block of code”. Mark for Review
(1) Points
True (*)
False
Correct
5. A Java program can be written in the single line. Mark for Review
(1) Points
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
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 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)
11. What is the correct way to cast a long to an int? Mark for Review
(1) Points
Correct
Correct
8
9 (*)
34
7
Correct
14. Which keyword makes a variable’s value unchangeable? Mark for Review
(1) Points
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
17. An Object cannot have String objects as properties. Mark for Review
(1) Points
True
False (*)
Correct
18. The print() method prints to the console and automatically creates a line. Mark for Review
(1) Points
True
False (*)
Correct
19. These two code fragments perform the same task. Mark for Review
// Fragment 1 (1) Points
String inputString = JOptionPane.showInputDialog("??");
int input = Integer.parseInt(inputString);
input++;
// 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
24. Identify the variable declared in the given code. Mark for Review
public class Welcome { (1) Points
public static void main(String args[]) {
int a = 2;
System.out.println("a is" + a);
}
}
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
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
27. The import statement consists of two parts. Mark for Review
import package.className; (1) Points
True (*)
False
Correct
28. The JFrame and JOptionPane classes are in the 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)
31. The String class must be imported using java.lang.String; Mark for Review
(1) Points
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 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 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
35. Methods allow all instance of a class to share same behaviors. 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)
36. Which of the following are the arguments in the following method? Mark for Review
Employee emp = new Employee(); (1) Points
emp.calculateSalary(100000, 3.2, 15);
Correct
37. You need to generate random integer values in the range 2 through 10. This code Mark for Review
fragment will produce the desired result.
(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 Mark for Review
statement should you use?
(1) Points
nextInt(81); (*)
nextInt(80);
nextInt();
nextInt(0-79);
Correct
39. Which class is used to generate random numbers? Mark for Review
(1) Points
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
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 4
(Answer all questions in this section)
41. What is the package name which contains Math class? Mark for Review
(1) Points
java.awt
java.net
java.lang (*)
java.io
Incorrect. Refer to Section 4 Lesson 5.
Section 5
(Answer all questions in this section)
42. A String comparison with == compares the Strings’ locations in memory and not the Mark for Review
content of the String.
(1) Points
True (*)
False
Correct
False
JavaProgramming
Java Programming
True (*)
Correct
Correct
45. How should Strings be compared? Mark for Review
(1) Points
Correct
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 5
(Answer all questions in this section)
46. An employee is eligible for a bonus based on certain criteria. Mark for Review
Under what conditions does “Eligible for a bonus” print?
(1) Points
int rating;
int experience;
if (rating > 1 && experience == 5) {
System.out.println (“Eligible for a bonus”);
}
Correct
47. A customer is eligible for a discount based on certain criteria. Under what conditions Mark for Review
does “You qualify for a discount” print? (Hint: There may be more than one correct
answer) (1) Points
int purchase;
int rewardPoints;
if (purchase >= 2000 || rewardPoints >= 4000) {
System.out.println("You qualify for discount");
}
Correct
48. Which two are not logical operators? Mark for Review
(1) Points
!
||
% (*)
+ (*)
&&
Correct
49. Which two statements are true about the default statement? Mark for Review
(1) Points
Correct
Correct