Java Language | 10 Minute‐Test 25


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.

What is the output of this program?

    class String_demo {

        public static void main(String args[])

        {

            char chars[] = {'a', 'b', 'c'};

            String s = new String(chars);

            System.out.println(s);

        }

   }

A.
a
B.
b
C.
c
D.
abc

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

String(chars) is a constructor of class string, it initializes string s with the values stored in character array chars, therefore s contains “abc”.

2.

What is the output of this program?

    class output {

        public static void main(String args[])

        {

            String a = "hello i love java";

            System.out.println(a.indexOf('i')+" "+a.indexOf('o') +" "+a.lastIndexOf('i')+" "+a.lastIndexOf('o'));

        }

    }

A.
6 4 6 9
B.
5 4 5 9
C.
7 8 8 9
D.
4 3 6 9

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

indexof(‘c’) and lastIndexof(‘c’) are pre defined function which are used to get the index of first and last occurrence of the character pointed by c in the given array.

3.

What is the output of this program?

    class output {

        public static void main(String args[])

        {

           String s1 = "one";

           String s2 = s1 + " two";

           System.out.println(s2);

        }

    }

A.
one
B.
two
C.
one two
D.
compilation error

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

4.

What is the output of this program?

    class output {

        public static void main(String args[])

        {

             StringBuffer c = new StringBuffer("Hello");

             c.delete(0,2);

             System.out.println(c);

        }

    }

A.
He
B.
Hel
C.
lo
D.
llo

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

delete(0,2) is used to delete the characters from 0 th position to 1 st position.

5.

What is the output of this program?

  class output { 

      public static void main(String args[]) { 

          StringBuffer sb=new StringBuffer("Hello"); 

          sb.replace(1,3,"Java"); 

          System.out.println(sb);

      } 

  }

A.
Hello java
B.
Hellojava
C.
HJavalo
D.
Hjava

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

The replace() method replaces the given string from the specified beginIndex and endIndex.

6.

What is the output of this program?

    class output {

        public static void main(String args[])

        {

           String s1 = "Hello i love java";

           String s2 = new String(s1);

           System.out.println((s1 == s2) + " " + s1.equals(s2));

        }

    }

A.
true true
B.
false false
C.
true false
D.
false true

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

The == operator compares two object references to see whether they refer to the same instance, where as equals() compares the content of the two objects.

7.

Which of the following package stores all the standard java classes?

A.
lang
B.
java
C.
util
D.
java.packages

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

8.

Which of the following package stores all the standard java classes?

A.
lang
B.
java
C.
util
D.
java.packages

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

9.

Which of the following package stores all the simple data types in java?

A.
lang
B.
java
C.
util
D.
java.packages

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

10.

What is the output of this program?

    class Output {

        public static void main(String args[]) {

            char a[] = {'a', '5', 'A', ' '};  

            System.out.print(Character.isDigit(a[0]) + " ");

            System.out.print(Character.isWhitespace(a[3]) + " ");

            System.out.print(Character.isUpperCase(a[2]));

        }

    }

A.
true false true
B.
false true true
C.
true true false
D.
false false false

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Character.isDigit(a[0]) checks for a[0], whether it is a digit or not, since a[0] i:e ‘a’ is a character false is returned. a[3] is a whitespace hence Character.isWhitespace(a[3]) returns a true. a[2] is an upper case letter i:e ‘A’ hence Character.isUpperCase(a[2]) returns true.


Submit your test now to view the Results and Statistics with answer explanation.