You are on page 1of 15

1.

 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 counter which gets incremented determines the number of loop
iterations is within the parentheses of a while loop.
The boolean expression that determines the number of loop iterations is
within the parentheses of a while loop. (*)
Correct

2. Which statement is false about infinite loop?


Mark for Review

(1) Points
The body of a while loop eventually must make the condition false to
avoid infinite loop.
An infinite loop is a code which will execute until the user interrupts the
program
An infinite loop is a commonly the result of a syntax error. (*)
An infinite loop is generally caused by a programming mistake.
Correct

3. A post-test loop evaluates its condition at the end of the loop instead
of the beginning.
Mark for Review

(1) Points
True (*)
False
Correct

4. Which is used to terminate a loop?


Mark for Review
(1) Points
continue
catch
break (*)
switch
Correct

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


understand the logic easily.
Mark for Review

(1) Points
True (*)
False
Correct
6. Which is not a looping statement in Java?
Mark for Review

(1) Points
switch (*)
for
do-while
while
Correct

7. Looping continues as long as the boolean expression in the for loop is


false.
Mark for Review

(1) Points
True
False (*)
Correct

8. Each expression in the header section of a for loop is optional.


Mark for Review

(1) Points
True (*)
False
Correct

9. A for loop is also called a definite loop


Mark for Review

(1) Points
True (*)
False
Correct
Section 7
(Answer all questions in this section)
10. If you need to make a particular variable belong to a class rather
than any individual instance, what type of variable should you use?
Mark for Review

(1) Points
A public variable.
A static variable. (*)
A local variable.
A private variable.
Correct
11. Static variables of a class can be accessed, even if the class has not
been instantiated.
Mark for Review

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

(1) Points
True (*)
False
Correct

13. How could you write the Employee constructor so that its parameters
are named the same as the fields they’re initializing?

public class Employee{


   private String name;
   private double salary;
   public Employee(String name, double salary){
     //initialize name
     //initialize salary
   }
}
Mark for Review

(1) Points
public Employee(String name, double salary){
   name = name;
   salary = salary;
}
public Employee(String name, double salary){
   name = this.name;
   salary = this.salary;
}
public Employee(String name, double salary){
   this.name = name;
   this.salary = salary;
} (*)
public Employee(String name, double salary){
   this.name = this.name;
   this.salary = this.salary;
}
Correct

14. Which two statements are NOT true about constructors?


Mark for Review

(1) Points
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

15. How would you instantiate the Employee class from a main method
located in another class?

public class Employee{


   private String name;
   private double salary;

   public Employee(String n, double s){


     name = n;
     salary = s;
   }
}
Mark for Review

(1) Points
Employee emp1 = new Employee();
Employee emp1 = new Employee(50000);
Employee emp1 = new Employee(50000, "Syam");
Employee emp1 = new Employee("Syam", 50000); (*)
Correct
16. Which has a default value of null?
Mark for Review

(1) Points
boolean
int
String (*)
double
Correct

17. Which two statements are true?


Mark for Review

(1) Points
An object can access another object’s public methods.(*)

An object can access another object’s public constructor.

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

An object can access another object’s main method.


Correct

18. What is encapsulation?
Mark for Review

(1) Points
A technique for including primitives within an ArrayList.
A technique for writing more than one main method.
A technique for limiting one class’s visibility to another. (*)
A technique for debugging.
Correct

19. Setters are void return type methods.


Mark for Review

(1) Points
True (*)
False
Correct

20. How would you complete this code so that one add method calls the
other add method?
public int add(int a, int b, int c) {
  return(a+b+c);
}
public int add(int a, int b){
  //Complete this line.
}
Mark for Review

(1) Points
return add(a, b, 0); (*)
return add(a, b, c);
return (a, b, c);
return (a, b);
Correct
21. Which three can vary in overloaded methods?
Mark for Review

(1) Points
Order of parameters.(*)

The names of parameters

Types of parameters.(*)

Number of parameters.(*)

Method return type.


Correct

22. All overloaded methods share the same name.


Mark for Review

(1) Points
True (*)
False
Correct

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


Mark for Review
(1) Points
Pass a variable as an argument to the method.
Use a return statement and define the method’s return type as non-
void (*)
Define a variable as a field member of the method
Define the method return type as void
Correct

24. Variables created within a method can be accessed outside that


method.
Mark for Review

(1) Points
True
False (*)
Correct

25. Which two statements are true about the main method?


Mark for Review

(1) Points
The main method should be able to freely manipulate an object’s fields.

The main method should be as simple as possible.(*)

The main method is commonly used to instantiate objects.(*)

The main method should store the properties and behaviors of objects.
Correct
26. Which keyword is used to allocate memory for a newly created
object?
Mark for Review

(1) Points
address
store
memory
new (*)
Correct
27. Java developers don't need to know an object’s location in memory.
Mark for Review

(1) Points
True (*)
False
Correct

28. Objects are accessed using reference variables.


Mark for Review

(1) Points
True (*)
False
Correct
Section 8
(Answer all questions in this section)
29. Each catch block is an exception handler that handles the type of
exception indicated by its argument.
Mark for Review

(1) Points
True (*)
False
Correct

30. If the try block succeeds then no exception has occurred.


Mark for Review

(1) Points
True (*)
False
Correct
Section 8
(Answer all questions in this section)
31. Which loop type is specially designed to traverse an array?
Mark for Review

(1) Points
repeat loop
do while loop
while loop
for loop (*)
Correct

32. What is the output?


int[] arr = new int[2];
for(int i=0; i < arr.length; i++){
   System.out.print("hai ");
}
Mark for Review

(1) Points
hai hai (*)
hai
12
hai hai hai
Correct

33. 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
012345
12345
01234 (*)
Correct

34. The Java compiler does not check for an


ArrayIndexOutOfBoundsException during the compilation of a program
containing arrays.
Mark for Review

(1) Points
True (*)
False
Correct

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


Mark for Review

(1) Points
True (*)
False
Correct
36. Which of the following is not a wrapper class?
Mark for Review

(1) Points
String (*)
Boolean
Byte
Integer
Correct

37. 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<Boolean> arrList = new ArrayList<>(); (*)
ArrayList<true, false> arrList = new ArrayList<>();
ArrayList<True, False> arrList = new ArrayList<>();
Correct

38. Which two cannot be stored in an ArrayList?


Mark for Review

(1) Points
float(*)

Integer

String

int(*)
Correct

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

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 semi-colon is missing.
A datatype is incorrect. (*)
A variable name is misspelled.
A variable hasn’t been assigned a value.
Correct
41. Which is not a compilation error?
Mark for Review

(1) Points
int y;
y++; (*)
y = 3 + * 5;
x = ( 3 + 5;
int x=2
Correct

42. What are two disadvantages of adding print statements for


debugging?
Mark for Review

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

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

Print statements cannot print the values of variables.

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


Correct
Section 9
(Answer all questions in this section)
43. Which is the correct syntax to instantiate a JavaFX Rectangle?
Mark for Review

(1) Points
Rectangle rect = Rectangle(20, 20, 100, 200);
Rectangle rect = new Rectangle(20, 20);
Rectangle rect = new Rectangle(20, 20, 100, 200); (*)
Rectangle rect = new Rectangle(20, 20, 100);
Correct
44. 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, 0);
Color customColor = Color.rgb(0, 0, 255);
Color customColor = Color.rgb(255, 255, 0);
Color customColor = Color.rgb(0, 255, 255); (*)
Correct

45. 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
46. An Image is an object that describes the location of a graphics file.
Mark for Review

(1) Points
True (*)
False
Correct

47. Which method is used to for mouse click events?


Mark for Review

(1) Points
setOnMouseDragged()
setOnMouseMoved()
setOnMouseReleased()
setOnMouseClicked() (*)
Correct
48. JavaFX is used to create GUI applications.
Mark for Review

(1) Points
True (*)
False
Correct

49. Which is not a JavaFX Node?


Mark for Review

(1) Points
Button
Object (*)
ScrollBar
ImageView
Correct

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

(1) Points
True (*)
False
Correct

You might also like