Test : Java_4

Apr 22, 2015
• Ekansh Rastogi

This test contains 10 questions based on Java. Each question answered correctly
awards you 1 point and each incorrect answer has a penalty of -0.25 points, no points are deducted for
unattempted answers.

Select Test Type

You Get +1 for each correct answer and -0.25 for each incorrect answer

Time Left - minutes :seconds

Class A

{

publicstaticvoid main(String a1[])

{

String s1= ?Hello?;

StringBuffer s2= new StringBuffer(?Hello?);

s1 = s1 + ?World?;

s2.append(?World?);

}

}

In the above code how many String and StringBuffer objects are created?

1 & 1

2 & 1

2 & 2

1 & 2

B

Difference between String and StringBuffer object is immutable and mutable
respectively. Code s1+ ?World? will create a new String object ?HelloWorld? with new reference is
assigned to s1 and looses ?Hello? String object reference. So two String object is created from the
above code.In the case of StringBuffer s2.append(?World?) will modify the existing object s2 and
creates only one object because it is mutable.

Which of these is used to access member of class before object of that class is created?

public

private

static

protected

C

Which of the following statements are true? (A) An abstract class may not have any final
methods. (B) A final class may not have any abstract methods. (C) An inner class may be declared with any
accessibility keyword. (D) Transient variables must be static.

B) & (C)

(A)

(A) & (C)

(D)

A

Which of these keywords are used to define an abstract class?

abst

abstract

Abstract

abstract class

B

Which of the following are the wrapper classes? (A) Random (B) Byte (C) Vector (D) Integer
(E) Short (F) Double (G) String

(B), (D) & (F)

(A), (B), (D), (E) & (F)

(B), (D), (E) & (F)

(D), (E) & (F)

C

Which of the following is correct way of implementing an interface salary by class
manager?