Professional Documents
Culture Documents
Nayak KCT,Coimbatore
Question 1
Question 2
Question 3
Question 4
Question 5
Question 6
1
Abhijit.A.Nayak KCT,Coimbatore
Question 7
Question 8
Question 9
Question 10
Question 11
Question 12
2
Abhijit.A.Nayak KCT,Coimbatore
Question 13
Question 14
To use an enum constant from out side of the class the only
way is to use fully qualified name i.e option D.
Refer page no 60 and 61 for similar examples
Question 15
Question 16
Question 17
3
Abhijit.A.Nayak KCT,Coimbatore
Question 18
Question 19
Question 20
Question 21
Question 22
Question 23
4
Abhijit.A.Nayak KCT,Coimbatore
Question 24
Question 25
Question 26
Go in sente
Go in goban
5
Abhijit.A.Nayak KCT,Coimbatore
Question 27
Question 28
Question 29
Question 30
Question 31
Question 32
This is an example to iterate through the enum elements
using the enhanced for loop. Color.values() is the type which
has to be passed in for the enum Color.
6
Abhijit.A.Nayak KCT,Coimbatore
Question 33
Question 34
Question 35
It is a straight forward question for the new For Each for loop.
Here Anonymous Array has been used to initialize the object
obj[] array. Somearray takes only integers as obj[] array has
been casted with (int[]) type.
Question 36
7
Abhijit.A.Nayak KCT,Coimbatore
Question 37
Question 38
Question 39
Question 40
Question 41
8
Abhijit.A.Nayak KCT,Coimbatore
Question 42
Question 43
Question 44
Question 45
Question 46
Question 47
9
Abhijit.A.Nayak KCT,Coimbatore
Question 48
Question 49
Simple but tricky flow since the subclass invokes the super
class default or no-args constructor but
there is no such constructor in class Person it fails to compile
(it fails to invoke the super
class constructor in line 18). So option D is correct.
Question 50
Question 51
Follow the flow to know the out put . Remember that this() is
used to invoke the current class constructors this. is used to
access the current object variables.
Question 52
Question 53
10
Abhijit.A.Nayak KCT,Coimbatore
Question 54
Question 55
Question 56
Question 57
Question 58
Question 59
Question 60
Question 61
11
Abhijit.A.Nayak KCT,Coimbatore
Question 62
Question 63
Question 64
Question 65
Question 66
12
Abhijit.A.Nayak KCT,Coimbatore
Question 67
Question 68
Question 69
Question 70
Question 71
13
Abhijit.A.Nayak KCT,Coimbatore
Question 72
Question 74
Question 75
Question 76
The question is tricky once the a.method1(); is called and then
b.method2(); is called from there and c.method3(); is called
from there.Remember NullPointerException is a Runtime
Exception.So all three methods need not handle/declare it.
c.method3(); propagates to b.method2();a.method1();
which is the calling code and it handles the exception.so
option E is right. The exception is caught by it and the lines
inside the catch executes. So option B is correct too.
Question 77
14
Abhijit.A.Nayak KCT,Coimbatore
Question 78
Question 79
Question 80
Exception is caught on line 14. But every time the finally runs
first and then the exception propagates to main and is caught
there.
Question 81
For question 82- please refer page 370 in the K&B text book.
Question 82
15
Abhijit.A.Nayak KCT,Coimbatore
Question 83
Question 84
java.lang.ExceptionlnlnitializerErrorThrown when
attempting to initialize a static variable or an initialization
block.
Question 85
Question 86
Question 87
Question 88
16
Abhijit.A.Nayak KCT,Coimbatore
Question 89
Question 90
Question 91
Question 92
Question 93
17
Abhijit.A.Nayak KCT,Coimbatore
Question 94
Question 95
Question 96
Question 97
Question 98
Question 99
18
Abhijit.A.Nayak KCT,Coimbatore
Question 100
Since there is no problem in code and no complex flow, it is a
general flow. So the corresponding values will be printed.
Refer page no 444 for similar example
Question 101
Question 102
Question 103
Question 104
Question 105
19
Abhijit.A.Nayak KCT,Coimbatore
This is simple .Refer page 471 and look at the valid instance
creation options.
Question 106
There is not method such like that setLocale. To set the locale
we need to create a
Locale object using the following syntax
Local locItaly=new Local(“it”,”IT”) and format() method is
available in
DateFormat class and it is not available in the Date class.
Refer page no 466,467 and 468
Question 107
Question 108
Question 109
Question 110
Question 111
20
Abhijit.A.Nayak KCT,Coimbatore
Question 112
Question 113
Question 114
Question 115
Calling run method wont start a new thread and wont throw
any error or exception, since calling run() is similar to calling
any other method so it is treated as just calling run()
method two times but it doesn’t start the thread.Calling
start() method makes the t.run(); t.run(); run . and then start
calls run();
So the run() method will be executed three times and out put
is “runnungrunningrunning”.
Refer page no 682 for the explanation on run() method.
Question 116
Question 117
21
Abhijit.A.Nayak KCT,Coimbatore
Question 118
Question 119
Question 120
Here the target for the thread t is a new instance of the class
thread2 which implements runnable.When t.start(); is invoked
run is printed for sure and Runtime exception is caught and
then End of method is also definitely printed.the order is
decided by the JVM.
Question 121
Question 122
22
Abhijit.A.Nayak KCT,Coimbatore
Question 123
Question 124
23
Abhijit.A.Nayak KCT,Coimbatore
Question 125
Question 126
Question 127
Question 128
24
Abhijit.A.Nayak KCT,Coimbatore
Question 129
Question 130
These are the 3 options which are the possible outputs but
The code may deadlock (without completing) with no output
is also correcting as “a” can be waiting for “b” and “b” can be
waiting for “a”
Question 131
Question 132
Wait and Notify should be applied for locking the object but
not thread.Here we are passing the Thread but not the object .
Correct examples are synchronized( this ) locks on the current
object,synchronized(MyClass.class) locks on the MyClass
object. But in this we are passing the Thread object.
Note: A thread acquires the lock on object.
Refer page nos 707,708,709
Question 133
25
Abhijit.A.Nayak KCT,Coimbatore
Question 134
Question 135
Here the string is public but the class is default . Since the
class has package level access u can access the String only in
the same package.
Question 136
Question 138
26
Abhijit.A.Nayak KCT,Coimbatore
FSame as option E.
Question 139
Question 140
Question 141
Question 143
Question 144
27
Abhijit.A.Nayak KCT,Coimbatore
Question 145
Question 146
Question 147
Question 148
28
Abhijit.A.Nayak KCT,Coimbatore
Question 149
Question 150
Question 151
Question 152
29
Abhijit.A.Nayak KCT,Coimbatore
Question 153
Question 154
Question 155
Aoverriding
Binvalid overriding
COverloading (long argument)
Dinvalid override return type cant be changed.
EOverloading ( long argument)
FOverloading
GOverloading
Question156
Question 157
Question 158
30
Abhijit.A.Nayak KCT,Coimbatore
Question 159
Question 160
Question 161
FTail tail; this is default access so Beagle can access the tail
So Beagle has a tail
Question 162
Question 163
31
Abhijit.A.Nayak KCT,Coimbatore
Question 164
Since ws1 ans ws2 are user defined objects they refer to the
different objects. But after creating s1, s1 will be placed in
String pool, when s2 is created the JVM sees that same
object is existing so s2 also refers to the s1 So s1 and s2 both
are fully equal. As per the HasSet rules only one object will be
taken the duplicate object will not be added. So in
total 3 objects will exist in the list ws1,ws2,s1
Question 165
The set variable contains only three elements from the coil
collection, but the order is NOT guaranteed to be
preserved.set s don’t take in duplicates and the elements
which are added inside are not in the same order.they are
randomly inserted.
Question 166
Question 167
So option D is correct.
Question 168
32
Abhijit.A.Nayak KCT,Coimbatore
Question 169
Question 170
Question 171
Question 172
Question 173
Question 174
33
Abhijit.A.Nayak KCT,Coimbatore
output is again 2
k1 is removed now k1 which is stored has a value of “i=1” so
it is checked using equals and also hashcode. And successfully
removed
output is one
k2.i=1 makes sure that “k2’s i” is not removed from the set
collection because while equals method and hashcode method
checks it equals return false and hashcode returns “ i=2” for
k2. hence output is one.
Option F is correct.
Question 175
Question 176
34
Abhijit.A.Nayak KCT,Coimbatore
Question 177
Question 178
Question 179
35
Abhijit.A.Nayak KCT,Coimbatore
Question 180
Question 181
Question 182
If we use the "?" place holder it takes any type object but it
not allows to add the objects to the list so the options A,B and
E are wrong (since we are having add method).
Refer page no 592, 596 and 610 for more information on ? and
? extends
Question 183
36
Abhijit.A.Nayak KCT,Coimbatore
Question 184
one.name= “Coffee”;
two.name= “Tea”;
these two lines makes sure that when they are added to the
set what happens is compare(object o) return a “zero” with it
and all the objects which are of type Drink are assumed to be
the same so while iterating over the collection we get Coffee
again n again.
Question 185
Question 186
Question 187
Question 188
The code is correct and when sorting spaces will come first
then caps and then smalls
so the output is C.
Refer page no 556 and 557 for sorting information
Question 189
37
Abhijit.A.Nayak KCT,Coimbatore
Question 190
Question 191
Question 192
Question 193
Question 194
Question 195
38
Abhijit.A.Nayak KCT,Coimbatore
Question 196
Question 197
Question 198
Question 199
Question 200
Question 201
java Yippee
39
Abhijit.A.Nayak KCT,Coimbatore
Question 202
java Yippee a b c
for(int x = 1; x < args.length; x++)
Question 203
Question 204
Question 205
Question 206
40
Abhijit.A.Nayak KCT,Coimbatore
Question 207
Question 208
The flow is
Question 209
Question 210
Question 211
Question 212
41
Abhijit.A.Nayak KCT,Coimbatore
6. doSomethingElse(o);
Here new object is created and passed to the line 6.
7.o = new Object();
here again new object is created and refered to variable “o”of
type Object .
8. doSomethingElse(null);
Now when null is passed through then the object “o” on line
5 will be refered to null. Not the new object created on line 7.
Hence on line 8,object “o” on line 5 becomes available for
garbage collection.
Question 213
Question 214
The correct syntax for using jar file with class path is
42
Abhijit.A.Nayak KCT,Coimbatore
Question 215
This question is very easy.just jolt down the path names and
the fully qualified names to classes and draw directories , the
option is jar A.
Question 216
43
Abhijit.A.Nayak KCT,Coimbatore
Question 217
OptionA
It is wrong because
44
Abhijit.A.Nayak KCT,Coimbatore
Question 218
Question 219
Since str is receiving the value null and we are applying the
length() method on the null object it throw
NullPointerException..
Question 220
45
Abhijit.A.Nayak KCT,Coimbatore
Question 221
Question 222
Question 223
Question 224
46