Java Programming Moc Test
Java Programming Moc Test
a. Array
c. String[][] s = new
String[5][];
d. String[][] s;
e. Array decaration: String[6]
strarray;
parameter list.
}
}
What will be the output of the above program?
Answer:
a. Prints 0
b. Prints:
01
c.
Prints: 10
d.
Prints
e. Compile-time
error
import java.util.*;
public class Code10 {
{
fnal Vector v;
v=new Vector();
}
public Code10() { }
public void codeMethod()
{ System.out.println(v.isE
mpty());
}
public static void main(String args[]) {
new Code10().codeMethod();
}
}
Which of the following will be the output for the
above code?
Answer:
a. Runtime error:
NullPointerException
b. Prints: false
c. Compilation error: cannot fnd the symbol
d. Prints:
true
e. Compilation error: v is not initialised inside the
constructor
b. Invoking
10
Which of the following options are true about abstract
implementations in
Collections?(choose 3)
Answer:
are supported
e. Map is not supported
11
12
13
The following class defnitions are in separate fles. Note that the
Widget and
BigWidget classes are in different packages:
1.
2.
3.
4.
5.
6.
7.
package conglomo;
public class Widget extends Object{
private int myWidth;
XXXXXX void setWidth( int n ) {
myWidth = n;
}
}
a. fnal
b. default (blank), that is, the method declaration
would read void setWidth( int n )
c. protected
d.private
e.public
14
b. It is polymorphic
d. Defned in the
Object class
e. Gives the String representation of an
Object
16
True False
tm.put("c","World");
Iterator it =
tm.keySet().iterator();
while(it.hasNext())
{ System.out.print(it.next()
);
}
}
}
What will be the output of the above code snippet?
Answer:
a. abc
b. Runtime
error c. HWJ
d. HelloJavaWorld
e. Compile error
17
}
public class IOCode5 {
public static void main(String args[]) throws
FileNotFoundException, IOException,
ClassNotFoundException {
ObjectOutputStream out = new ObjectOutputStream(new
FileOutputStream("C:/ObjectD
ata")); Test2 t1 = new
Test2();
t1.a = 20;
t1.b = 30;
out.writeObject(
t1); out.close();
ObjectInputStream in = new ObjectInputStream(new
FileInputStream("C:/ObjectData"));
Test2 t2 = (Test2) in.readObject(); // Line 1
System.out.println(t2);
}
}
What will be the output of the above code
snippet? Answer: a. a = 10, b = 30
b. a = 0, b = 30
c. a = 20, b =
30
d. a = 10, b = 0
e. throws TransientException at the commented line (//
Line 1)
19
a. java.io
b. java.util
c. java.lang
d.
java.lang.annotati
on
e.java.sql
20
Which of the following will be the output for the above code?
Answer: a. 0 1 2 3 4 0 1 2
34
b. 0 1 2 3 4 5
c. 0 1 2 3 4
21
p
r
o
t
e
c
t
e
d
S
t
r
i
ng name;
d. 1 2 3 4 5
e. Indefnite Loop
Director(String name) {
this.name = name;
}
abstract void occupation();
}
class FilmDirector extends
Director { FilmDirector(String
name) { super(name);
}
void occupation() {
System.out.println("Director " + name + " directs flms");
}
}
public class TestDirector {
public static void main(String[] args) {
FilmDirector fd = new FilmDirector("Manirathnam");
fd.occupation();
new Director("Manirathnam") {
void occupation() {
System.out.println("Director " + name + " also produces flms");
}
}.occupation();
}
}
Which of the following will be the output of the above code
snippet?
Answer: a. Compilation fails at TestDirector class
b. Prints: Director Manirathnam also produces
flms
c. Prints: Director Manirathnam directs flms
Director Manirathnam also produces flms
d. Prints: Director Manirathnam directs flms
e. Runtime
Error
22
False.
Answer: True
23
False
a. Map
b. Set
c. Queue
d. List
24
Which of the following modifier cannot be applied to the
declaration of a feld
(member of a class)?
Answer: a. protected
b. private
c. fnal
d. public
e. abstract
25
26
}
d. public class Test4 {
static int main(String args[]) {
System.out.println("Test4");
}
}
e. public class Test5 {
static void main(String[] data)
{
System.out.println("Test5");
}
}
27
28
b. char[][][] charArray =
29
30
31
d. @Override
e. @deprecated
32
33
34
35
System.out.print(s1.concat(s2.substring(1, s1.length())).length());
}
}
What will be the output of the following code snippet?
Answer: a. 18 20
b. 17 19
c. 20 18
d. 17 17
e. 19 17
36
37
storage device
e. to run fnalize methods explicitly
38
39
thrown by JVM
b. All RuntimeException are thrown by JVM
c. JVM cannot throw user-defned exceptions
d. All exceptions are thrown programmatically from the
code or
API
e. JVM thrown exceptions can be thrown
programmatically
40
41
Which of the following options is true about multi-level
inheritance?
Answer: a. Inheriting from two super classes
b. Inheriting from a class which is already in an
inheritance hierarchy
c. Inheriting from more than one
super class d. Inheriting from a single
class
42
43
class C extends B {
// insert code here
}
Which of the following code fragments, when inserted
individually at the commented line (// insert code here), makes
use of polymorphism? (Choose 3)
Answer:
44
c.
NavigableLis
t d. Deque
45
a. node1.node = null;
b. node1 = node1.node;
c. node1.node = new
Node();
d. node1 = null;
e. node1 = new Node();