Hi all,
The following are some sample 310-055 (
Java 5.0) questions.
The difficulty level is moderate-difficult.
Have fun answering them.
Please do reply on how good/bad you found the questions to be/
Q1 . Given the following
1 class base1
2 {
3 void display()
4 {
5 System.out.println("Base display");
6 }
7 }
8
9 class student extends base1
10 {
11 void display()
12 {
13 System.out.println("student display");
14 }
15
16 void details()
17 {
18 System.out.println("student details");
19 }
20 }
21
22 public class teacher extends student
23 {
24 void display()
25 {
26 System.out.println("teacher display");
27 }
28
29 public void details()
30 {
31 System.out.println("Teacher details");
32 }
33 public static void main(
String args[])
34 {
35 student s1=new student();
36 s1.details();
37 teacher t=new teacher();
38 t.details();
39 s1=t;
40 s1.details();
41 base1 b1=new base1();
42 b1=s1;
43 b1.display();
44 b1.details();
45 }
46 }
What is the result?
A) Student details
teacher details
student details
base display
student details
B) Student details
teacher deatails
teacher details
teacher display
student details
C) Student details
teacher deatils
student display
teacher display
teacher details
D) Student details
teacher details
teacher details
teacher display
teacher display
E) Compilation error
F) Exception thrown at runtime.
************************************************************
Q2. Given the following :
1 public class temp
2 {
3 static int x=0;
4 temp(int x)
5 {
6 x=x+1;
7 }
8 temp()
9 {
10 x++;
11 }
12
13 public static void main(String args[])
14 {
15 temp t=new temp(10);
16 System.out.println("The value of static variable is "+temp.x);
17 temp t2=new temp();
18 System.out.println("The value of static variable is "+temp.x);
19 }
20 }
What is the result ?
A) 11
12
B) 10
11
C) 11
11
D) 11
1
E) 0
1
*******************************************
Q19 Given the following
1 class game
2 {
3 protected static void play()
4 {
5 System.out.println("play game ");
6 }
7 }
8
9 class hockey extends game
10 {
11
12 public static void play()
13 {
14 System.out.println("play hockey");
15 }
16
17 }
18
19 public class foot extends hockey
20 {
21
22 public static void play()
23 {
24 System.out.println("play football");
25 }
26
27 public static void main(String args[])
28 {
29 foot f=new foot();
30 f.play();
31 hockey h=new hockey();
32 h.play();
33 h=f;
34 h.play();
35
36 }
37
38
39 }
What is the result :
A) playing football
playing hockey
playing football
B) playing football
playing hockey
playing hockey
C) Compilation error at line 12
D) Compilation error at line 22
E) Compilation error at line 33
F) Exception thrown at run time.
**********************************************
Q18 Given
1 public class
test 2 {
3 static int i=0;
4 test()
5 {
6 i++;
7 }
8
9 public static void main(String args[])
10 {
11 test t=new test();
12 System.out.print(test.i);
13 test t1=new test();
14 System.out.print(test.i);
15 test2=new test();
16 System.out.print(test.i);
17 }
18 }
What is the result
A) 1 1 1
B) 0 0 0
C) 1 2 3
D) Code does not compile at line 14
E) Exception thrown at runtime
****************************************************
Q17) Given the following
1 class A
2 {
3 final int x=10;
4 protected final void message()
5 {
6 System.out.println("A");
7 }
8 protected void getValue()
9 {
10 System.out.println(x);
11 }
12 }
13 public class B extends A
14 {
15 public void message()
16 {
17 System.out.println("B");
18 }
19 public static void main(String args[])
20 {
21 A obj1=new A();
22 obj1.message();
23 B obj2=new B();
24 obj2.message();
25 obj1=obj2;
26 obj1.message();
27 obj1.getValue();
28 }
29 }
What is the result ?
A) A
B
B
10
B) A
B
A
10
C) Compilation fails at line 15
D) Compilation fails at line 25
E) Compilation fails at line 27
[ September 02, 2008: Message edited by: ElanKumaran Srinivasan ]