Java Language | 10 Minute‐Test 21


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 obtain length of String object?

A.
get()
B.
Sizeof()
C.
lengthof()
D.
length()

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

Method length() of string class is used to get the length of the object which invoked method length().

2.

In below code, what can directly access and change the value of the variable name?

package test;

 class Target

 {

  public String name = "hello";

 }

A.
any class
B.
only the Target class
C.
any class in the test package
D.
any class that extends Target

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Any class in the test package can access and change name.

3.

Which of these method of class String is used to remove leading and trailing whitespaces?

A.
startsWith()
B.
trim()
C.
Trim()
D.
doTrim()

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

4.

What is the output of this program?

    class overload {

        int x; int y;

        void add(int a){ 

           x =  a + 1; 

       }    

    void add(int a , int b){  

          x =  a + 2;   

     }    

        }      

  class Overload_methods {    

    public static void main(String args[])  

      {      

      overload obj = new overload();    

           int a = 0;    

        obj.add(6, 7);  

          System.out.println(obj.x);   

          } 

 }

A.
6
B.
7
C.
8
D.
9

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

5.

Which of these method of class StringBuffer is used to reverse sequence of characters?

A.
reverse()
B.
reverseall()
C.
Reverse()
D.
reverseAll()

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

reverse() method reverses all characters. It returns the reversed object on which it was called.

6.

Which of these method of class String is used to check weather a given object starts with a particular string literal?

A.
startsWith()
B.
endsWith()
C.
Starts()
D.
ends()

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Method startsWith() of string class is used to check whether the String in question starts with a specified string. It is specialized form of method regionMatches()

7.

Which of this access specifies can be used for a class so that its members can be accessed by a different class in the same package?

A.
Public
B.
Protected
C.
No Modifier
D.
All of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

Either we can use public, protected or we can name the class without any specifier.

8.

Which of these access specifiers can be used for an interface?

A.
Public
B.
Protected
C.
private
D.
All of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Access specifier of interface is either public or no specifier. When no access specifier is used then default access specifier is used due to which interface is available only to other members of the package in which it is declared, when declared public it can be used by any code.

9.

Which of these is a super class of wrappers Double & Integer?

A.
Long
B.
Digits
C.
Float
D.
Number

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

Number is an abstract class containing subclasses Double, Float, Byte, Short, Integer and Long.

10.

Which of these is a super class of wrappers Long, Character & Integer?

A.
Long
B.
Digits
C.
Float
D.
Number
Submit your test now to view the Results and Statistics with answer explanation.