File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

New java questions

 
ElanKumaran Srinivasan
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for posting. However when you post a question here it is required to tell us where these questions are from. Did you write them on your own ?
 
Bert Bates
author
Sheriff
Posts: 8898
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also after telling us the source, please format the code using the code tags.

Thanks,

Bert
 
subhasish nag
Ranch Hand
Posts: 101
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
answer 1:
compiler error in line b1.details();
because details() method is not overriden in student class.
answer 2:
0 ,1 as in test(int x) constructor value of local variable is changing.

answer 19
play footba
play hockey
play hockey

because satic method play() can't be overriden.It's only hidding.

answer 18
compiler error in line test2=new test();
answer 17
comiler error in line 15. because final method can't be overriden
[ September 02, 2008: Message edited by: subhasish nag ]
 
ElanKumaran Srinivasan
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I wrote the questions myself and wanted to know if they are up to the standard.

Here's one more..

3 Given the following

1 class base

2 {

3 int x=0;

4 base()

5 {

5 x++;

6 }

7 base (int i)

8 {

9 --x;

10 }

11 }

12

13 public class child extends base

14 {

15 child()

16 {

17 ++x;

18 }

19 child(int x)

20 {

21 this();

22 x++;

23 }

24

25 public static void main(String args[])

26 {

27 child c=new child(10);

28 System.out.println("The value of x is "+c.x);

29 }

30 }





What is the result ?

A) The value of x is 12

B) The value of x is 11

C) The value of x is 13

D) The value of x is 1

E) The value of x is 2

F) None of the above is the correct answer
 
Ankit Garg
Sheriff
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice work Elan Kumaran.

However as an advice I would say that your questions are concentrated on a single type of gotcha...I am not saying that they are bad but they are a little repetitive.

But don't be discouraged. Your work is great. I am giving you a tip for improvement.....
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A tip which Bert already posted above: If you use code tags, the forum software will automatically format your Java code.
 
ElanKumaran Srinivasan
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ankit, I will try to write better questions.

Jesper and Bates, thanks for the tip.Will try to make use of the code tags next time onwards.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic