Beruflich Dokumente
Kultur Dokumente
An infinite loop is a code which will execute until the user interrupts the program
The body of a while loop eventually must make the condition false to avoid infinite
loop.
Correct
Statements in the loop are executed repeatedly until the condition becomes false.
Statements in the loop are executed once initially, and then the condition is
evaluated.
Statements in the loop are executed once until the condition becomes false.
The number of times a do-while loop is executed is dependent upon the value of
the counter variable. (*)
3. After the loop is terminated, the statement immediately following the loop body is
executed. Mark for Review
(1) Points
True (*)
False
Correct
4. In the given syntax of for loop, which part represents the header section?
Mark for Review
for (initialization; condition; update) { (1) Points
// Code statement(s) }
Code statement(s)
5. You want to compute the sum of all the marks of a given subject. Which approach will
you choose? Mark for Review
(1) Points
if/else statement
switch statement
Looping (*)
if statement
Correct
Correct
7. Which two operators cannot be used as the conditional expression in a for loop?
Mark for Review
(1) Points
<
==
!< (*)
!=
!> (*)
Correct
8. A continue statement is used to skip the remaining statements in the body of a loop
and continue with the next iteration of the loop. Mark for Review
(1) Points
True (*)
False
Correct
The execution of the program will continue with the statement following the
loop-statement. (*)
The execution of the program will stop at the statement following the loop-
statement.
When a break statement is executed inside a loop, the loop-statement is
terminated immediately. (*)
When a break statement is executed inside a loop, the loop-statement is
terminated immediately and comes out of the program.
Section 7
(Answer all questions in this section)
True (*)
False
Correct
Use a return statement and define the method’s return type as non-void (*)
Correct
12. You have created an Employee class with all required fields and methods. 10
employees join the company. Should you copy and paste the Employee class for all 10 Mark for Review
employees? (1) Points
True
False (*)
Correct
True (*)
False
Correct
The purpose of a getter method is to return the value of a private field (*)
The purpose of a getter method is to grant other classes access to public data.
The purpose of a setter method is to allow private data to be modified safely (*)
Correct
Correct
Correct
True (*)
False
Correct
Correct
20. A constructor is a special method which is commonly used to set the initial values of
an object’s fields. Mark for Review
(1) Points
True (*)
False
Correct
21. In Java, the this keyword can be used to reference the current object’s fields and
methods. Mark for Review
(1) Points
True (*)
False
Correct
22. How would you instantiate the Employee class from a main method located in another
class? Mark for Review
(1) Points
public class Employee{
private String name;
private double salary;
Correct
23. What will happen when you try to access an object reference with a null value?
Mark for Review
(1) Points
NullPointerException. (*)
Correct
s1: Hello
s2: Hello
s1: Welcome!
s2: Hello
s1: Welcome!
s2: Welcome! (*)
s1: Hello
s2: Welcome!
Correct
25. Java automatically clears the memory once occupied by an object using garbage
collection. Mark for Review
(1) Points
True (*)
False
Correct
Instance variables
Objects
Strings
Correct
27. Given the following code, why does your IDE complain that “non-static variable name
cannot be referenced from a static context”? Mark for Review
(1) Points
public class Employee{
public static int employeeID;
public String name;
Correct
28. The fields and methods of the Math class cannot be directly accessed as they are
static. Mark for Review
(1) Points
True
False (*)
Correct
Section 8
(Answer all questions in this section)
29. Which exception is thrown when an application attempts to use null when an object is
required? Mark for Review
(1) Points
NullPointerException (*)
FileNotFoundException
ArithmeticException
ArrayIndexOutOfBoundsException
Correct
30. What is the danger of catching a generic Exception type as shown below?
Mark for Review
int[] array = {10, 20, 30}; (1) Points
int b = 0;
try{
System.out.println("1");
int c = (array[3] / b);
System.out.println("2");
}
catch(Exception ex){
System.out.println(ex.toString());
}
The details of the Exception object ex are too general to be useful. (*)
int x=2
int y;
y++; (*)
y = 3 + * 5;
x = ( 3 + 5;
Correct
32. Using the NetBeans debugger, you can set breakpoints and trace through a program
one line at a time. Mark for Review
(1) Points
True (*)
False
Correct
A semi-colon is missing.
Correct
True (*)
False
Correct
35. An array allows you to create a single identifier that can be used to organize many
items of the same data type. Mark for Review
(1) Points
True (*)
False
Correct
36. Which loop type is specially designed to traverse an array?
Mark for Review
(1) Points
repeat loop
while loop
do while loop
10 (*)
ArrayIndexOutOfBoundsException
Correct
38. You can access the size of any array by using the array’s “length” property.
Mark for Review
(1) Points
True (*)
False
Correct
True (*)
False
Correct
ListIterator
iterator
True (*)
False
Correct
42. Which two are limitations of an array of primitives (ie: int[] x)?
Mark for Review
(1) Points
You need to create your own methods to manipulate array contents. (*)
The size of the array is fixed during array creation and cannot grow once
initialized. (*)
Section 9
(Answer all questions in this section)
True (*)
False
Correct
44. How would you set the title of the Stage primaryStage?
Mark for Review
(1) Points
primaryStage("New Title!");
Correct
ScrollBar
Object (*)
Button
ImageView
46. When you write code for MouseEvents, you are telling a Node to listen for a particular
event. Mark for Review
(1) Points
True (*)
False
Correct
True (*)
False
Correct
48. Which method is used to for mouse click events?
Mark for Review
(1) Points
setOnMouseClicked() (*)
setOnMouseDragged()
setOnMouseMoved()
setOnMouseReleased()
Correct
49. How would you create a custom color that is pure cyan (equal parts green and blue)?
Mark for Review
(1) Points
Correct
setX(double d)
setStrokeWidth(double d) (*)
setStroke(Paint paint)
setLayoutX(double d)