Académique Documents
Professionnel Documents
Culture Documents
5
Part -I
Max Marks: 30
Convener: Dinesh Kumar
Important Instructions
This Question Paper contains a total of 30 questions. All questions are
mandatory.
All the questions are objective type and may have more than one
option correct. Each question carries 1 mark. There is no negative
marking.
An answer to the question is considered to be correct only if all correct
option(s) are chosen by student.
Trainees need to score minimum 50% marks to pass this exam.
A
C
A
B
B
IS-A B
IS-A A
HAS-A C
HAS-A A
HAS-A C
A
B
Compilation fails.
An exception is thrown at runtime.
A)
B)
C)
D)
E)
F)
instantiate a parent
");
//--------------------------------------------
A)
B)
C)
D)
E)
F)
instantiate a child
instantiate a child
instantiate a parent
instantiate a child
instantiate a parent
instantiate a parent
instantiate a child
Compilation fails.
An exception is thrown at runtime.
");
instantiate a parent
");
instantiate a child
}
A)
B)
C)
D)
E)
F)
instantiate a child
instantiate a parent
instantiate a child
instantiate a parent
instantiate a parent
instantiate a child
Compilation fails.
An exception is thrown at runtime.
");
" +
i +
");
A)
B)
C)
D)
sub
super 2
super 2
sub
Compilation fails.
An exception is thrown at runtime.
);
A)
B)
C)
D)
E)
F)
4
4 8
8 4
8 4 no-arg
no-arg 8 4
Compilation fails.
(x * 2) +
x +
no-arg
);
");
);
no-arg
8 4 no-arg
no-arg 8 4
Compilation fails.
No output is produced.
An exception is thrown at runtime.
);
");
);
Beagle() { }
Beagle() { super(); }
Beagle() { super("fido"); }
Do Not provide any explicit constructor, allow the default
constructor only.
Question 10) Given the following code, which line of code, inserted at
indicated position, will NOT compile?
public class Test
{
public static void main(String ar[])
{
int x;
x = test();
}
static int test()
{
// --position -- insert code here
return y;
}
}
A)
B)
C)
D)
E)
short y = 7;
int y = (int) 7.2d;
Byte y = 7;
char y = 's';
int y = 0xface;
Question 11). Which digits, and in which order, will be printed when the
following program is run?
public class MyClass {
public static void main(String[] args) {
int k=0;
try {
int i = 5/k;
} catch (ArithmeticException e) {
System.out.println("1");
} catch (RuntimeException e) {
System.out.println("2");
return;
} catch (Exception e) {
System.out.println("3");
} finally {
System.out.println("4");
}
System.out.println("5");
}
}
Select the one correct answer.
A)
B)
C)
D)
E)
F)
The
The
The
The
The
The
program
program
program
program
program
program
will
will
will
will
will
will
only
only
only
only
only
only
print
print
print
print
print
print
5.
1 and 4, in that order.
1, 2, and 4, in that order.
1, 4, and 5, in that order.
1, 2, 4, and 5, in that order.
3 and 5, in that order.
Question 12) Given the following code, which of the following code
fragments inserted at indicated position will NOT compile?
import java.util.*;
class Ro
{
public static void main(String... args)
{
Ro r = new Ro();
Object o = r.test();
}
Object test()
{
//insert code here
}
}
A) return null;
B) Object t = new Object();
return t;
C) int [] a = new int [2];
return a;
D) char [] [] c = new char [2][2];
return c[0] [1];
E) char [] [] c = new char [2][2];
return c[1];
F) return 7;
Question 13). What will be the result of attempting to compile and run the
following program?
public class MyClass {
public static void main(String[] args) {
RuntimeException re = null;
throw re;
}
}
Select the one correct answer.
A) The code will fail to compile, since the main() method does not declare
that it throws RuntimeException in its declaration.
B) The program will fail to compile, since it cannot throw re.
C) The program will compile without error and will throw
java.lang.RuntimeException when run.
D) The program will compile without error and will throw
java.lang.NullpointerException when run.
E) The program will compile without error and will run and terminate
without any output.
Question 14) Which statements are NOT true about super() or this()?
A) A super() or this()call must always be provided explicitly as the first
statement in the body of a constructor.
B) If both a subclass and its super-class do not have any declared
constructors, the implicit default constructor of the subclass will call
super()when run.
C) If neither super() or this() is declared as the first
statement in the body of a constructor, then this() will be
implicitly inserted as the first statement.
D) If super() is the first statement in the body of a constructor, then
this() can be declared as second statement.
E) Calling super() as the first statement in the body of a constructor of a
subclass will always work, since all super-classes
have default
constructor.
Question 16) For the class Employee given in above Question # 15, what is
the output when following code is executed?
public class ParamTest
{
public static void main(String[] args)
{
Employee a = new Employee("Alice", 70000);
Employee b = new Employee("Bob", 60000);
swap(a, b);
System.out.print(a.getName()+ );
System.out.print(b.getName()+ );
}
public static void swap(Employee x, Employee y)
{
Employee temp = x;
x = y;
y = temp;
System.out.print(x.getName()+ );
System.out.print(y.getName() + );
}
}
A)
B)
C)
D)
E)
F)
Compilation fails.
Exception is generated at runtime
Alice Bob Alice Bob
Bob Alice Bob Alice
Bob Alice Alice Bob
Alice Alice Bob Bob
Compilation fails.
Exception is generated at runtime
A B C A
C C A B
A C A C
A B B A
C C C B
Compilation fails.
Exception is generated at runtime
A B C A
B C A B
A B A C
A B B A
A B C B
");
A. Flip a Clidlet
B. Flip a Clidder
C. Flip a Clidder
Flip a Clidlet
D. Flip a Clidlet
Flip a Clidder
E. Compilation fails.
");
A. Clidlet
B. Clidder
C. Clidder
Clidlet
D. Clidlet
Clidder
E. Compilation fails.
012
012122
Compilation fails at line 7.
Compilation fails at line 8.
Compilation fails at line 9.
An exception is thrown at runtime.
void dol()
{
}
}
//------class Y extends X
{
void do2()
{
}
}
//-------class Chrome
{
public static void main(String [] args)
{
X x1 = new X();
X x2 = new Y();
Y y1 = new Y();
// insert code here
}
}
A. x2.do2( );
B. (Y) x2. do2( );
C. ((Y)x2).do2();
D. None of the above statements will compile.
true true
false true
true false
false false
Compilation fails.
An exception is thrown at runtime.
Question 30) Consider the following code, with line numbers prefixed on
every line, watch carefully the case-sensitivity
1. class Convert {
2.
public static void main(String[] args) {
3.
Long xL = new Long(456L);
4.
long x1 = Long.valueOf("123");
5.
Long x2 = Long.valueOf("123");
6.
long x3 = xL.longValue();
7.
Long x4 = xL.longValue();
8.
Long x5 = Long.parseLong("456");
9.
long x6 = Long.parseLong("123");
10. }
11. }
Which lines of code will compile using Java 5, but will NOT compile using
Java 1.4?
A)
B)
C)
D)
E)
F)
Line
Line
Line
Line
Line
Line
4.
5.
6.
7.
8.
9.
!! End of Exam !!