Java Language | 10 Minute‐Test 22


Instruction

  • Total number of questions : 10.
  • Time alloted : 10 minutes.
  • Each question carry 1 mark.
  • No Negative marks
  • DO NOT refresh the page.
  • All the best :-).

1.

Which of these method of class String is used to extract a single character from a String object?

A.
CHARAT()
B.
chatat()
C.
charAt()
D.
ChatAt()

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

2.

What will be output of the following code?

public class Boxer1 {

    Integer i;

    int x;

 public Boxer1(int y) {

    x = i+y;

    System.out.println(x);

 }

 public static void main(String[] args) {

    new Boxer1 (new Integer(4));

 }

}

A.
The value “4” is printed at the command line
B.
Compilation fails because of an error in line
C.
A NullPointerException occurs at runtime
D.
An IllegalStateException occurs at runtime

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

Because we are performing operation on reference variable which is null.

3.

What is the value returned by function compareTo() if the invoking string is greater than the string compared?

A.
zero
B.
value less than zero
C.
value greater than zero
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

if (s1 == s2) then 0, if(s1 > s2) > 0, if (s1 < s2) then < 0.

4.

What is the string contained in s after following lines of code?
StringBuffer s new StringBuffer(“Hello”);
s.deleteCharAt(0);

A.
Hell
B.
ello
C.
Hel
D.
llo

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

deleteCharAt() method deletes the character at the specified index location and returns the resulting StringBuffer object.

5.

Which of these method of class StringBuffer is used to get the length of sequence of characters?

A.
length()
B.
capacity()
C.
Length()
D.
Capacity()

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

length()- returns the length of String the StringBuffer would create whereas capacity() returns total number of characters that can be supported before it is grown.

6.

What is the value returned by unction compareTo() if the invoking string is less than the string compared?

A.
zero
B.
value less than zero
C.
value greater than zero
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

compareTo() function returns zero when both the strings are equal, it returns a value less than zero if the invoking string is less than the other string being compared and value greater than zero when invoking string is greater than the string compared to.

7.

Which of these access specifiers can be used for a class so that it’s members can be accessed by a different class in the different package?

A.
Public
B.
Protected
C.
Private
D.
No Modifier

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

8.

Which of these keywords is used by a class to use an interface defined previously?

A.
import
B.
Import
C.
implements
D.
Implements

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

interface is inherited by a class using implements.

9.

Which of these is wrapper for simple data type float?

A.
float
B.
double
C.
Float
D.
Double

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

10.

Which of these is wrapper for simple data type char?

A.
Float
B.
Character
C.
String
D.
Integer
Submit your test now to view the Results and Statistics with answer explanation.