0% found this document useful (0 votes)
65 views

A. False A. False: B. True

1. The document contains a name, email address, and 48 multiple choice questions related to Java programming. 2. The questions cover topics like Java keywords, variables, data types, operators, arrays, methods, classes, inheritance and exceptions. 3. Correct answers are provided for each multiple choice question to test the knowledge of Java programming concepts and syntax.

Uploaded by

Jimmy Rosero
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

A. False A. False: B. True

1. The document contains a name, email address, and 48 multiple choice questions related to Java programming. 2. The questions cover topics like Java keywords, variables, data types, operators, arrays, methods, classes, inheritance and exceptions. 3. Correct answers are provided for each multiple choice question to test the knowledge of Java programming concepts and syntax.

Uploaded by

Jimmy Rosero
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Name : Mauricio alexander Pantoja Cabrera

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

a. False 9. Does a call to System.gc() force garbage


b. True collection to take place? (assuming there are
objects to be collected)
3. A variable name can start with $?
a. Not always
a. False b. Yes always
b. True
10. Which of these operators would cause the
4. Which of these are legal values for a bit pattern 00111100 to become 11000011?
boolean?
a. ~
a. 1,0 b. –
b. true, false c. !
c. true, false, 1, 0
d. TRUE, FALSE, 11. Assume:
e. TRUE, FALSE true, false
int li_x = 2 and li_y = 4;
5. What is the bit-depth of a char?
What is the result of:
a. 7 bits
b. 8 bits (!(li_y > li_x));
c. 16 bits
d. 32 bits a. false
b. true
6. What is the bit-depth of a byte?
12. Assume:
a. 7 bits
b. 8 bits int li_x = 6; li_y = 7;

7. A floating point literal in Java is treated as a? What is the result of:

a. Double (!(li_x == li_y))


b. double
c. Float a. false
d. Float b. true
13. Assume: 19. Methods which are marked protected can be
called on any subclass of the class in which the
byte lb_a = 3, lb_b = 2; method is declared?

What is the result of: a. False


b. True
byte lb_c = lb_a + lb_b;
20. Can a private method of a superclass be
a. lb_c = 3 declared within a subclass?
b. lb_c == 5
c. Compiler error a. No
d. Runtime error b. Yes

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

X lx_x = new Y();

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

42. Is this legal?


48. What happens when you put this expression
public static void main (String[] in your code?
asa_fred)
int li_x = 0;
a. No int li_y = 4 % x;
b. Yes
a. Compiler error
43. Assume li_x = 3 and li_y = 0. What is the b. Compiles and runs
value of li_x after? 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?

51. What happens when you compare two a. No


primitives of different numerical types? b. Yes

a. Compiler error 58. If a final variable is a reference to an object,


b. Must explicitly cast can that object’s data member be modified
c. Smaller type is promoted while the program is running?

52. Which of these is the Exclusive-Or (XOR) a. No


operator? b. Yes

a. ~ 59. Can a final method be overridden?


b. ^
c. & a. No
d. Is the regular or operator b. Yes

60. Can you automatically convert a long int to


an int if the long value is small enough to fit
53. into an int?
boolean lb_false = false, lb_true = true;
a. No
What is the result of? b. Yes

lb_false && lb_true

a. false 61. Can you automatically/implicitly convert a


b. true char to a short?

54. Can a method have more than one access a. No


modifier? b. Yes

a. No 62. Can you pass a short into a method call


b. Yes when an int is expected?

55. Can a subclass access the private members a. No


of its own superclass? b. Yes

a. No 63. Given this code, what prints?


b. Yes
boolean lb_b = false;
if(lb_b=true) System.out.println(“yes”);
a. Nothing prints 71. Constructors can not be overloaded?
b. “yes” prints
a. False
64. If you do not use curly braces for a while b. True
loop body, what will execute if the while
condition is true? 72. An inner class has free access to private
member data of the outer classes?
a. First statement after while()
b. Nothing a. False
b. True
65. Using a break in a for loop causes the loop
to break out of the current iteration and jump to 73. Member (instance) variable are always
the next iteration of the loop assigned a default value if not explicitly
initialized?
a. False
b. True a. False
b. True
66. An exception can be caught by a catch
block with an argument type that is a superclass 74. Automatic (local) variables are always
of the thrown exception? assigned a default value if not explicitly
initialized?
a. False
b. True a. False
b. True
67. In a try/catch, an exception will not be
considered caught if the catch(Exception) block 75. When you pass a variable as an argument to
has no code within the braces? a method call, what are you passing?

a. False a. A copy of the value


b. True b. The actual value

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

a. Argument list 77. When using the right-shift operator (>>),


b. Return type what happens to the bits which moves off the
c. Return type AND argument list right end?

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

79. 86. Can a constructor be declared private?


boolean lb_x = true, lb_y = false;
a. No
What is the result of lb_x & lb_y? b. Yes

a. Compiler error 87. Can a constructor be declared abstract?


b. false
c. true a. No
b. Yes
80. Can one object access a private variable of
another object of the same class? 88. Can a constructor be declared static?

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?

82. Static variables are implicitly final? a. No


b. Yes
a. False
b. True 91. Can you pass a double to a method when
the method’s argument is a float?
83. It is legal to access a static method using an
instance of the class? a. No
b. Yes
a. No
b. Yes 92. Class Y is a subclass of class X. Will this
compile?
84. Are static methods allowed to access
instances variables using this.var? Y ly_y = new Y();
X lx_x = ly_y;
a. No
b. Yes a. No
b. Yes
99. If a method A declares that it throws an
93. Using a break in a for loop causes the loop exception and method B calls method A, then
to break out of the current iteration and jump to method B must ALWAYS declare the same
the next iteration of the loop? exception?

a. False a. False
b. True b. True

94. Is this legal? 100. Class A inherits from B. B includes a


method with the same name, return type and
int li_i = 0; argument list as a method in A. This is a sample
of
if(li_i){}
a. Overloading
a. No b. Overriding
b. Yes
101. A class can define two methods with the
95. In a switch statement, the argument to the same name as long as the return types are
case label (case: argument) can be any variable different?
which can fit within an int?
a. False
a. False b. True
b. True
102. An overriding method of a subclass can
96. In a switch construct, once a matching value throw an ArithmeticException not thrown by
is found, execution will continue through other the original (overridden) method?
case labels until it reaches a break statement?
a. False
a. False b. True
b. True
103. Overloaded methods must not throw new
97. In a switch construct, the default statement checked exceptions not thrown by the original
must be placed after all the case statements? method?

a. False a. False
b. True b. True

104. An inner class has a free access to ALL


member data of its enclosing (outer) class?
98. All exceptions inherit from?
a. False
a. java.lang.Error b. True
b. java.lang.Exception
c. java.lang.Throwable 105. It is not possible to have an instance of a
non-static inner class before any instances of
the outer class have been created?

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?

107.public class Outer{int ii_x;static class a. Change its sign


Inner(){void foo(){ii_x = 5;}}} b. Keep it negative

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. Compiler error a. False


b. doStuff() in A b. True
c. doStuff() in B
d. Runtime error 116. Methods which have no access modifier
can only be accessed by classes within the same
109. Are you allowed to have more than one package?
top-level (non-inner) class definition per source
file? a. False
b. True
a. No
b. Yes 117. Methods which are marked protected can
be accessed only by classes within the same
110. Each source file must have a public class package?
in it?
a. False
a. No b. True
b. Yes
118. Can a public method by overriding by a
111. Assume the bit value of byte lb_x is protected method?
00101011. What is the result of lb_x >> 2?
a. No
a. 00001010 b. Yes
b. 11001010
119. Methods and variables can be declared as 128. Can a member variable be declared
final, but a class cannot be declared final? synchronized?

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++;

123. Can an abstract method be overridden? a. Compiles and runs


b. Runtime error
a. No c. Won’t compile without cast
b. Yes
132. Class Y is a subclass of class X. Will this
124. Can a class be declared native? compile?

a. No X lx_x = new X();


b. Yes Y ly_y = (Y) lx_x;

125. Can a member variable be declared native? a. No


b. Yes
a. No
b. Yes 133. In switch statement, the argument to the
switch can be a variable as long as it is
126. Can a method be declared transient? compatible with an int

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)

137. A finally block will only be executed if the a. False


exception is not caught b. True

a. False 145. Can a method be declared volatile?


b. True
a. No
b. Yes

146. Is cast a keyword?


138. A MalformedURLException is a checked
exception? a. No
b. Yes
a. False
b. True
147. What is the result of the following code?
139. An ArithmeticException is a checked
exception? System.out.println(Math.round(-3.22));

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

159. What will be the output of this code?


152. Will this compile?
class Exam{protected String is_difficultyLevel
int lia_x[5] = new int[] {1, 2, 3, 4, 5}; =”easy”;public void printDifficultyLevel()
{System.out.println(is_difficultyLevel);}}class
a. No SCJPExam extends Exam{private String
b. Yes is_difficultyLevel =”killing”; }{ …new
SCJPExam(). printDifficultyLevel();…}
153. Assuming all variables are declared and
initialized properly, will this compile? a. easy
b. killing
for(li_i = 1, li_j = 2; li_i < 3; li_i++,
li_j++){}; 160. An anonymous inner class cannot have a
constructor?
a. No
b. Yes a. False
b. True
154. Assuming all variables are declared and
initialized properly, will this compile? 161. A method cannot be declared as throwing
more than one exception?
for(li_i = 1; li_k < 5; li_j++){};
a. False
a. No b. True
b. Yes

You might also like