Java Language | 10 Minute‐Test 24


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 is an incorrect statement?

A.
String objects are immutable, they cannot be changed
B.
String object can point to some other reference of String variable.
C.
StringBuffer class is used to store string in a buffer for later use.
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

StringBuffer class is used to create strings that can be modified after they are created.

2.

What is the output of this program?

    class output {

        public static void main(String args[])

        {

           String c = "Hello i love java";

           int start = 2;

           int end = 9;

           char s[]=new char[end-start];

           c.getChars(start,end,s,0);

           System.out.println(s);

        }

    }

A.
Hello, i love java
B.
i love ja
C.
lo i lo
D.
llo i l

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

getChars(start,end,s,0) returns an array from the string c, starting index of array is pointed by start and ending index is pointed by end. s is the target character array where the new string of letters is going to be stored and the new string will be stored from 0th position in s.

3.

What is the output of this program?

    class output {

        public static void main(String args[])

        {

           String c = "  Hello World  ";

           String s = c.trim();

           System.out.println("\""+s+"\"");

        }

    }

A.
“”Hello World””
B.
“”Hello World”
C.
“Hello World”
D.
Hello world

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

trim() method is used to remove leading and trailing whitespaces in a string.

4.

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('e')+" "+a.indexOf('a')+" "+a.lastIndexOf('l')+" "+a.lastIndexOf('v'));

        }

    }

A.
6 4 6 9
B.
5 4 5 9
C.
7 8 8 9
D.
1 14 8 15

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.

5.

What is the output of this program?

    class output {

        public static void main(String args[])

        {

             StringBuffer c = new StringBuffer("Hello");

             System.out.println(c.length());

        }

    }

A.
4
B.
5
C.
6
D.
7

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

length() method is used to obtain length of StringBuffer object, length of “Hello” is 5.

6.

What is the output of this program?

    class output {

        public static void main(String args[])

        {

           String c = "Hello i love java";

           boolean var;

           var = c.startsWith("hello");

           System.out.println(var);

        }

    }

A.
true
B.
false
C.
0
D.
1

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

startsWith() method is case sensitive “hello” and “Hello” are treated differently, hence false is stored in var.

7.

Which of the following is incorrect statement about packages?

A.
Package defines a namespace in which classes are stored.
B.
A package can contain other package within it.
C.
Java uses file system directories to store packages.
D.
A package can be renamed without renaming the directory in which the classes are stored.

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

A package can be renamed only after renaming the directory in which the classes are stored.

8.

Which of the following is incorrect statement about packages?

A.
Interfaces specifies what class must do but not how it does.
B.
Interfaces are specified public if they are to be accessed by any code in the program.
C.
All variables in interface are implicitly final and static.
D.
All variables are static and methods are public if interface is defined pubic.

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

All methods and variables are implicitly public if interface is declared public.

9.

Which of these methods is used to check for infinitely large and small values?

A.
isInfinite()
B.
isNaN()
C.
Isinfinite()
D.
IsNaN()

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

isinfinite() method returns true is the value being tested is infinitely large or small in magnitude.

10.

Which of these methods is used to obtain value of invoking object as a long?

A.
long value()
B.
long longValue()
C.
Long longvalue()
D.
Long Longvalue()
Submit your test now to view the Results and Statistics with answer explanation.