A. False A. False: B. True
A. False A. False: B. True
Date : [email protected]
1. All Java keywords are written in lower case? 8. When you pass a reference to an array as an
argument to a method call, you pass a new
a. False reference to the original array?
b. True
a. False
2. A method name can start with a number? b. True
14. Can you compare a boolean to an integer? 21. Can an abstract class have non-abstract
methods?
a. No
b. Yes a. No
b. Yes
15. What is “instanceof”?
22. Can a non-abstract class have abstract
a. A method in Object methods?
b. An operator
a. No
16. b. Yes
Integer li_a = new Integer(5);
Integer li_b = new Integer(5); 23. If a non-abstract class X inherits abstract
methods from its abstract parent class Y, is the
What is the result of running: class X required to implement the inherited
abstract methods?
if(li_a == li_b)
a. No
a. Compiler error b. Yes
b. false
c. Runtime exception 24. If a class declares that it implements an
d. True interface B (class A implements B), must be
class A implement the methods of interface B?
17. Can a top-level class be marked as private?
a. Under ALL circumstances
a. No b. Unless A is abstract
b. Yes
25. During arithmetic, when the operands are of
18. Can a top-level class be marked as different types, the resulting type is ALWAYS
protected? the wider of the two types?
a. No a. False
b. Yes b. True
26. Class Y is a subclass of class X. Will this 32. An inner class must be defined within the
compile? opening and closing braces of a class, but
outside any method, just like other members?
Y ly_y = new X();
a. False
a. No b. True
b. Yes
33. A class defined within a parameter to a
method is:
a. Anonymous
27. Class Y is a subclass of class X. Will this b. Illegal
compile? c. Static
a. No
b. Yes 34. When an object is created using new(), its
constructor will not complete until all
28. Can you compile an if construct without constructors higher on the inheritance tree have
using curly braces? complete?
a. No a. False
b. Yes b. True
29. What goes in the first part of a for loop? 35. The compiler will always insert a default,
no argument constructor into any class
a. Boolean test definition?
b. Init statement
c. Iteration expression a. False
b. True
30. Is this legal?
36. When you override a method the overriding
int li_i; method in the subclass must not be declare
ANY new exceptions not declared by the
for(li_i = 4, int li_t = 6; li_i < 0; li_i++) overridden method?
a. No a. False
b. Yes b. True
31. In a for loop, the continue statement will 37. Will this compile?
cause execution to jump out of the loop and
continue on at the first statement below the float lf_f = 27.24f;
loop?
a. No
a. False b. Yes
b. True
38. As a literal, what is 27.24? a. li_x == li_y
b. li_x < li_y
a. A double c. li_x > li_y
b. A float
45. Integer literals are always what size?
39. Will this compile?
a. byte – 8 bits
int lia_x = [27]; b. int – 16 bits
c. int – 32 bits
a. No d. int – 64 bits
b. Yes e. short – 16 bits
40. When an array is constructed, are its 46. Can you use an increment unary operator on
elements automatically initialized? a byte? (example byte lb_b = 4; lb_b++;)
a. No a. Never
b. Yes b. Yes
c. With explicit cast
41. Is this legal?
47. What happens when you divide an integer
int lia_x[] ={2, 7, 4, 9}; by a variable with a value of 0?
a. No a. Compiler error
b. Yes b. Compiles and runs
c. Runtime exception
li_x = li_y++; 49. What happens when you have this in your
code?
a. 3
b. 4 double ld_d;
c. 7
ld_d = 24.0 / 0;
44. Given
a. Compiler error
li_x = li_y--; b. Compiles and runs
c. Runtime exception
Which of these will be true after execution?
50. What happens when you bit shift by a 56. Can a method with no access modifier be
number greater than or equal to the number of overridden by a method marked protected?
bits in the result? (e.g. int li_c = 270; li_c >>
33) a. No
b. Yes
a. You get -1
b. You get 0 57. Does a final member variable have to be
c. You get 270 >> 1 initialized at the time it’s declared?
68. If an exception is not caught, the finally 76. When you pass an object reference as an
block will run and the rest of the method is argument to a method call, what gets passed?
skipped?
a. False a. A copy of the reference
b. True b. A reference to a copy
c. The object itself
69. An overloaded method MUST change? d. The original reference
70. Overloaded methods are free to change the a. They wrap around
access modifier? b. They’re added to the result
c. They’re gone
a. False
b. True
78. boolean lb_x = true, lb_y = true;What is the 85. The only things which can be defined inside
result of lb_x ^ lb_y? a class and outside a method are instance
variables and inner classes?
a. Compiler error
b. false a. False
c. true b. True
a. No a. No
b. Yes b. Yes
81. For object lo_x to access a method of object 89. Is this legal?
lo_y, when the method has no access modifier,
object lo_x MUST be an instance of a class float lf_f = 2;
which is
a. No
a. A subclass of lo_y b. Yes
b. Declared public
c. In the same package as lo_y 90. Can you automatically convert an int into a
d. The same class as lo_y double?
a. False a. False
b. True b. True
a. False a. False
b. True b. True
a. False
b. True
c. 10101100
106. This is a legal way to create in instance of
an inner class? 112. Assume the bit pattern of byte lb_b is:
10110001. What will the sign of lb_b be after
OuterClass.InnerClass lic_ic = new lb_b>>2?
OuterClass().new InnerClass();
a. Negative
a. False b. Positive
b. True
113. What does the unsigned right-shift
operator do to a negative number?
a. Compiles
b. Does not compile 114. What is the result of 00110011 &
11110000
108. Class B extends A. B overrides the
doStuff() method inherited from A. Which a. 00000000
method gets called if you say: b. 00110000
c. 11110011
A la_a = new B();
115. The short-circuit operators work on
la_a. doStuff(); boolean types, not bits?
a. False a. No
b. True b. Yes
120. Can a final class be subclassed? 129. Can a class be declared synchronized?
a. No a. No
b. Yes b. Yes
121. Can you have a final abstract class? 130. Can a method be declared synchronized?
a. No a. No
b. Yes b. Yes
122. Can a member variable be declared 131. What happens when you compile this?
abstract?
byte lb_b = 2;
a. No
b. Yes lb_b++;
a. No a. False
b. Yes b. True
127. Can a class be declared transient? 134. In a switch construct, the default statement
will always execute?
a. No
b. Yes a. False
b. True
135. In a switch construct, the default statement 142. To invoke an overridden method from the
will execute if no case values match the method which overrides it, use?
switch() argument?
a. super.theMethod();
a. False b. this.theMethod();
b. True
143. Constructors are not inherited
136. In a try catch construct, the catch blocks
may be written in any order and the most a. False
narrow/specific catch argument is chosen at b. True
runtime
144. It is legal to declare an array with an
a. False interface as the type (instead of a class or
b. True primitive) (e.g. PetInterface [] lpia_p)
a. False a. -4
b. True b. -4.0
c. -3
140. If a try / catch calls System.exit(), the d. -3.0
finally block will execute first?
a. False
b. True
148. What is the result of the following code?
141. An overriding method can change the
access modifier from default to protected? System.out.println(Math.ceil(-3.22));
a. False a. -4
b. True b. -4.0
c. -3
d. -3.0
149. What is the result of the following code? 155. If you do not provide any constructor for
System.out.println(Math.floor(-3.22)); your class, the compiler will insert a default
constructor with public access modifier?
a. -4
b. -4.0 a. False
c. -3 b. True
d. -3.0
156. An interface can extend at most one
150. What is the result of the following code? interface?
System.out.println(Math.sqrt(-4)); a. False
b. True
a. -2
b. -2.0 157. An abstract class can have a constructor?
c. 2
d. 2.0 a. No
e. NaN b. Yes
151. Will this compile? 158. If there is a return statement in the catch
block, the finally block will not be executed?
int lia_x[] = new int[] {1, 2, 3, 4, 5};
a. False
a. No b. True
b. Yes