Sunteți pe pagina 1din 17

Section 6

(Answer all questions in this section)

1. After the loop is terminated, the statement immediately following


the loop body is executed. Mark for Review
(1) Points

True (*)

False

Incorrect Incorrect. Refer to Section 6 Lesson 2.

2. A do-while will always execute statements contained in the loop


at least once. Mark for Review
(1) Points

True (*)

False

Correct Correct

3. Which statement is true? Mark for Review


(1) Points

A while loop boolean expression is made up of a counter, increment, and test.

A counter (i) is declared and initialized inside the while loop.

The boolean expression that determines the number of loop iterations is


within the parentheses of a while loop. (*)

The counter which gets incremented determines the number of loop iterations
is within the parentheses of a while loop.

Incorrect Incorrect. Refer to Section 6 Lesson 2.

4. Which is not a looping statement in Java? Mark for Review


(1) Points
do-while

for

switch (*)

while

Correct Correct

5. The initialization expression initializes the loop and it is


executed only once, as the loop begins. Mark for Review
(1) Points

True (*)

False

Correct Correct
Section 6
(Answer all questions in this section)

6. A for loop is also called a definite loop Mark for Review


(1) Points

True (*)

False

Correct Correct

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


for Review
(1) Points

for (int i = 1; i < 10; i += 2) {


System.out.print(i + " ");
}

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 = 2; i <= 10; i += 2) {


System.out.print(i + " ");
} (*)

Correct Correct

8. What is the result?

public static void main(String[] args) {


for (int var1 = 0; var1 < 2; var1++) {
for (int var2 = 0; var2 < 2; var2++) {
if (var2 == 2) {
continue;
}
System.out.println("var1:" + var1 + ", var2:" + var2);
}
}
}
Mark for Review
(1) Points

var1: 0, var2: 0
var1: 0, var2: 1
var1: 1, var2: 0
var1: 1, var2: 1
var1: 2, var2: 0
var1: 2, var2: 1

var1: 0, var2: 0
var1: 0, var2: 1
var1: 1, var2: 0
var1: 1, var2: 1

(*)

var1: 0, var2: 0
var1: 0, var2: 1
var1: 0, var2: 2
var1: 1, var2: 0
var1: 1, var2: 1
var1: 1, var2: 2
var1: 2, var2: 0
var1: 2, var2: 1
var1: 2, var2: 2
var1: 0, var2: 0
var1: 1, var2: 1
var1: 2, var2: 0

Correct Correct

9. The purpose of adding comments is to increase the ability to


understand the logic easily. Mark for Review
(1) Points

True (*)

False

Incorrect Incorrect. Refer to Section 6 Lesson 3.

Section 7
(Answer all questions in this section)

10. All overloaded methods share the same name. Mark for Review
(1) Points

True (*)

False

Correct Correct
Section 7
(Answer all questions in this section)

11. Methods can call other methods in the same class. Mark for
Review
(1) Points

True (*)

False
Correct Correct

12. Method overloading can be a useful technique for defining methods


with similar functionality or calculations. Mark for Review
(1) Points

True (*)

False

Correct Correct

13. The fields and methods of the Math class cannot be directly
accessed as they are static. Mark for Review
(1) Points

True

False (*)

Correct Correct

14. Static variables of a class can be accessed, even if the class


has not been instantiated. Mark for Review
(1) Points

True (*)

False

Correct Correct

15. 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 Correct
Section 7
(Answer all questions in this section)

16. Which two statements are NOT true about constructors? Mark for
Review
(1) Points

(Choose all correct answers)

A constructor method may return a value. (*)

A constructor method is called once for each instance of an object.

The constructor method is called during instantiation.

A constructor method has a void return type. (*)

Correct Correct

17. 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.

Correct Correct

18. When you write your own constructor, the default constructor is
no longer available. Mark for Review
(1) Points
True (*)

False

Correct Correct

19. 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 Correct

20. In this statement, identify the type of the variable s.

Student s = new Student(); Mark for Review


(1) Points

String

Class

Student (*)

null

Correct Correct
Section 7
(Answer all questions in this section)

21. Which is stored within the stack memory? Mark for Review
(1) Points

Objects

Strings
Instance variables

Local variables (*)

Incorrect Incorrect. Refer to Section 7 Lesson 2.

22. In the following statements, how many employee objects are


created?

Employee e1 = new Employee();


Employee e2 = new Employee();
Employee e3 = new Employee();
Mark for Review
(1) Points

3 (*)

Correct Correct

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


Mark for Review
(1) Points

True (*)

False

Correct Correct

24. 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 employees? Mark for Review
(1) Points

True
False (*)

Correct Correct

25. First, you decide the radius of each circle in the logo. Then
using the same radius you draw 5 circles of same size. All these circles will have
properties like radius and color. All circles share behaviors to calculate
circumference and area. Can you identify which of the following is an object?
Mark for Review
(1) Points

fiveCircles

radius

circle (*)

circumference

Correct Correct
Section 7
(Answer all questions in this section)

26. To make fields directly accessible to other classes, the class


fields must be marked public. Mark for Review
(1) Points

True (*)

False

Correct Correct

27. An object reference directs you from one object to another. Mark
for Review
(1) Points

True (*)

False
Correct Correct

28. Which two statements are true? Mark for Review


(1) Points

(Choose all correct answers)

An object can access another object�s public fields. (*)

An object can access another object�s public constructor.

An object can access another object�s main method.

An object can access another object�s public methods. (*)

Correct Correct

Section 8
(Answer all questions in this section)

29. Which is NOT a benefit of ArrayList class? Mark for Review


(1) Points

An ArrayList grows as you add elements.

An ArrayList shrinks as you remove elements.

You can use an ArrayList list to store Java primitive values (like int). (*)

You can remove all of the elements of an ArrayList with a method.

Correct Correct

30. How could you declare an ArrayList so that it can store true or
false values? Mark for Review
(1) Points

ArrayList<boolean> arrList = new ArrayList<>();


ArrayList<true, false> arrList = new ArrayList<>();

ArrayList<Boolean> arrList = new ArrayList<>(); (*)

ArrayList<True, False> arrList = new ArrayList<>();

Correct Correct
Section 8
(Answer all questions in this section)

31. The size of an ArrayList can grow as needed. Mark for Review
(1) Points

True (*)

False

Correct Correct

32. Which of the following is not a wrapper class? Mark for Review
(1) Points

String (*)

Byte

Integer

Boolean

Correct Correct

33. If the try block succeeds then no exception has occurred. Mark
for Review
(1) Points

True (*)

False
Correct Correct

34. What is the danger of catching a generic Exception type as shown


below?

int[] array = {10, 20, 30};


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());
} Mark for Review
(1) Points

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 Incorrect. Refer to Section 8 Lesson 3.

35. What is an array? Mark for Review


(1) Points

An array is a way to create multiple copies of a single value.

An array is an indexed container that holds a set of values of a multiple


types.

An array is an indexed container that holds a set of values of a single type.


(*)

An array is a Java primitive type.

Correct Correct
Section 8
(Answer all questions in this section)
36. 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 Correct

37. Arrays are like variables which must be declared prior to use.
Mark for Review
(1) Points

True (*)

False

Correct Correct

38. What is the output?


int[] arr = new int[5];
for(int i=0; i<arr.length; i++){
arr[i] = i;
}
for(int i=0; i<arr.length; i++) {
System.out.print(arr[i]);
} Mark for Review
(1) Points

123

12345

01234 (*)

012345

Correct Correct

39. What are two advantages of adding print statements for debugging?
Mark for Review
(1) Points

(Choose all correct answers)

You can identify compilation errors.

You can identify which methods have been called. (*)

You can identify the order in which methods have been called. (*)

You can identify runtime errors.

Correct Correct

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

int radiusOfCircle = 10;


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

A datatype is incorrect. (*)

A variable hasn�t been assigned a value.

A semi-colon is missing.

A variable name is misspelled.

Correct Correct
Section 8
(Answer all questions in this section)

41. What are two disadvantages of adding print statements for


debugging? Mark for Review
(1) Points

(Choose all correct answers)

Print statements cannot print the values of variables.

It�s tedious to remove print statements. (*)

Too many print statements lead to information overload. (*)


Print statements cannot print the values of an object�s fields.

Incorrect Incorrect. Refer to Section 8 Lesson 4.

42. Which is not a compilation error? Mark for Review


(1) Points

int x=2

x = ( 3 + 5;

int y;
y++; (*)

y = 3 + * 5;

Correct Correct

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 Correct

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

primaryStage = "New Title!;

primaryStage("New Title!");
primaryStage.title = "New Title!";

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

Correct Correct

45. The start() method is the entry point for all JavaFX
applications. Mark for Review
(1) Points

True (*)

False

Correct Correct
Section 9
(Answer all questions in this section)

46. JavaFX Ensemble contains code examples of JavaFX features. Mark


for Review
(1) Points

True (*)

False

Correct Correct

47. Which color is not directly used when creating custom


Color.rgb()? Mark for Review
(1) Points

Blue

Red

Green

Yellow (*)
Correct Correct

48. Lambda Expressions provide much more effective and cleaner syntax
for working with GUI applications and sorting lists. Mark for Review
(1) Points

True (*)

False

Correct Correct

49. Which method is used to for mouse click events? Mark for Review
(1) Points

setOnMouseReleased()

setOnMouseClicked() (*)

setOnMouseMoved()

setOnMouseDragged()

Correct Correct

50. JavaFX doesn�t provide you with UI elements, shapes and text. So
you must always create your own graphics. Mark for Review
(1) Points

True

False (*)

Correct Correct

S-ar putea să vă placă și