Sie sind auf Seite 1von 14

1. Which statement is false about infinite loop?

Mark for Review


(1) Points

An infinite loop is a code which will execute until the user interrupts the program

An infinite loop is generally caused by a programming mistake.

An infinite loop is a commonly the result of a syntax error. (*)

The body of a while loop eventually must make the condition false to avoid infinite
loop.

Correct

2. Which statement is NOT true about do-while loops?


Mark for Review
(1) Points

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. (*)

Incorrect. Refer to Section 6 Lesson 2.

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) }

for (initialization; condition; update) { Code statement(s) }

Code statement(s)

for (initialization; condition; update) (*)

for (initialization; condition; update) { }


Correct

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

6. Which statement will produce the output: 2, 4, 6, 8, 10?


Mark for Review
(1) Points

for (int i = 0; i < 8; i += 2) {


System.out.print(i + " ");
}
for (int i = 0; i < 10; i += 2) {
System.out.print(i + " ");
}
for (int i = 1; i < 10; i += 2) {
System.out.print(i + " ");
}
for (int i = 2; i <= 10; i += 2) {
System.out.print(i + " ");
} (*)

Correct

7. Which two operators cannot be used as the conditional expression in a for loop?
Mark for Review
(1) Points

(Choose all correct answers)

<

==

!< (*)

!=

!> (*)
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

9. Which two statements are true about the break statement?


Mark for Review
(1) Points

(Choose all correct answers)

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.

Incorrect. Refer to Section 6 Lesson 3.

Section 7
(Answer all questions in this section)

10. The structure of a class consists of properties and behaviors.


Mark for Review
(1) Points

True (*)

False

Correct

11. How can you retrieve a value from a method?


Mark for Review
(1) Points
Define the method return type as void

Define a variable as a field member of the method

Pass a variable as an argument to the method.

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

13. Access and visibility of a class should be limited as much as possible.


Mark for Review
(1) Points

True (*)

False

Correct

14. Which two statements are true?


Mark for Review
(1) Points

(Choose all correct answers)

The purpose of a setter method is to modify a public field

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

15. What is encapsulation?


Mark for Review
(1) Points
A technique for limiting one class’s visibility to another. (*)

A technique for debugging.

A technique for including primitives within an ArrayList.

A technique for writing more than one main method.

Correct

16. Given the method:


Mark for Review
void add(double a, double b) (1) Points

Which method signature would not overload this method?

void add(int a, int b, int c)

void add(String a, String b)

void add(int a, int b)

int add (double a, double b) (*)

void add (double a, int b)

Correct

17. All overloaded methods share the same name.


Mark for Review
(1) Points

True (*)

False

Correct

18. Which three can vary in overloaded methods?


Mark for Review
(1) Points

(Choose all correct answers)

Types of parameters. (*)

Number of parameters. (*)

Method return type.

Order of parameters. (*)


The names of parameters

Correct

19. Which statement is true about the default constructor of a class?


Mark for Review
(1) Points

Java automatically provides a constructor for every class. (*)

You must write a default constructor.

The default constructor always returns void.

Default constructor should have at least one argument.

Incorrect. Refer to Section 7 Lesson 3.

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;

public Employee(String n, double s){


name = n;
salary = s;
}
}

Employee emp1 = new Employee();

Employee emp1 = new Employee(50000);

Employee emp1 = new Employee(50000, "Syam");

Employee emp1 = new Employee("Syam", 50000); (*)

Correct

23. What will happen when you try to access an object reference with a null value?
Mark for Review
(1) Points

NullPointerException. (*)

The value null is retrieved from the memory location.

An empty object is returned.

You will get a compilation error.

Correct

24. What is the output of the following code?


Mark for Review
String s1 = "Hello"; (1) Points
String s2 = "Welcome!";
s1 = s2;
System.out.println("s1: " +s1);
System.out.println("s2: " +s2);

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

26. Which is stored within the stack memory?


Mark for Review
(1) Points

Local variables (*)

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;

public static void display(){


System.out.println(employeeID);
System.out.println(name);
}
}

Static variables cannot be referenced from methods.

The variable name has a null value.

It would be possible to call the display() method and attempt to reference an


object’s name before any object exists. (*)
Static variables are only accessible from instance methods.

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. (*)

An Exception will never occur.

An ArithmeticException cannot be caught.

An ArrayIndexOutOfBoundsException cannot be caught.

Incorrect. Refer to Section 8 Lesson 3.

31. Which is not a compilation error?


Mark for Review
(1) Points

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

33. Identify where there is a potential bug in this code:


Mark for Review
int radiusOfCircle = 10; (1) Points
int areaOfCircle = Math.PI * radiusOfCircle * radiusOfCircle;

A datatype is incorrect. (*)

A variable hasn’t been assigned a value.

A semi-colon is missing.

A variable name is misspelled.

Correct

34. Testing and debugging are important activities in software development.


Mark for Review
(1) Points

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

for loop (*)

repeat loop

while loop

do while loop

Incorrect. Refer to Section 8 Lesson 1.

37. What is the output?


int[] arr = new int[1]; Mark for Review
arr[0] = 10; (1) Points
System.out.println(arr[0]);

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

39. The size of an ArrayList can grow as needed.


Mark for Review
(1) Points

True (*)

False

Correct

40. Which is not used to traverse an ArrayList?


Mark for Review
(1) Points
for-each loop

ListIterator

do- while loop (*)

iterator

Incorrect. Refer to Section 8 Lesson 2.

41. You can access elements in an ArrayList by their index.


Mark for Review
(1) Points

True (*)

False

Correct

42. Which two are limitations of an array of primitives (ie: int[] x)?
Mark for Review
(1) Points

(Choose all correct answers)

You need to create your own methods to manipulate array contents. (*)

You can create only one array in a class.

You cannot overwrite the contents of an array once initialized.

The size of the array is fixed during array creation and cannot grow once
initialized. (*)

Incorrect. Refer to Section 8 Lesson 2.

Section 9
(Answer all questions in this section)

43. A layout Pane dictates how Nodes must be positioned


Mark for Review
(1) Points

True (*)

False
Correct

44. How would you set the title of the Stage primaryStage?
Mark for Review
(1) Points

primaryStage.title = "New Title!";

primaryStage = "New Title!;

primaryStage("New Title!");

primaryStage.setTitle("New Title!"); (*)

Correct

45. Which is not a JavaFX Node?


Mark for Review
(1) Points

ScrollBar

Object (*)

Button

ImageView

Incorrect. Refer to Section 9 Lesson 1.

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

47. Audio can be played by referencing the Audio object directly.


Mark for Review
(1) Points

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

Color customColor = Color.rgb(0, 255, 255); (*)

Color customColor = Color.rgb(255, 255, 0);

Color customColor = Color.rgb(0, 255, 0);

Color customColor = Color.rgb(0, 0, 255);

Correct

50. Which method helps to set the width of a rectangle’s outline?


Mark for Review
(1) Points

setX(double d)

setStrokeWidth(double d) (*)

setStroke(Paint paint)
setLayoutX(double d)

Incorrect. Refer to Section 9 Lesson 2.

Das könnte Ihnen auch gefallen