349). Which of these class is superclass of String and StringBuffer class?
[A]java.util
[B] java.lang
[C]ArrayList
[D]None of the mentioned
Show Answer
Correct Answer: java.lang
Notes:
Answer: b
Explanation: None.
350). Which of these operators can be used to concatenate two or more String objects?
Show Answer
Correct Answer: +
Notes:
Answer: a
Explanation: Operator + is used to concatenate strings, Example String s = “i ” + “like ” + “java”; String s contains “I like java”.
351). Which of this method of class String is used to obtain a length of String object?
[A]get()
[B] Sizeof()
[C]lengthof()
[D] length()
Show Answer
Correct Answer: length()
Notes:
Answer: d
Explanation: Method length() of string class is used to get the length of the object which invoked method length().
352). 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()
Show Answer
Correct Answer: charAt()
Notes:
Answer: c
Explanation: None.
353). Which of these constructors is used to create an empty String object?
[A]String()
[B]String(void)
[C]String(0)
[D]None of the mentioned
Show Answer
Correct Answer: String()
Notes:
Answer: a
Explanation: None.
354). 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
Show Answer
Correct Answer: StringBuffer class is used to store string in a buffer for later use
Notes:
Answer: c
Explanation: StringBuffer class is used to create strings that can be modified after they are created.
355). What will be the output of the following Java program?
class String_demo
{
public static void main(String args[])
{
char chars[] = {'a', 'b', 'c'};
String s = new String(chars);
System.out.println(s);
}
}
Show Answer
Correct Answer: abc
Notes:
Answer: 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”.
output:$ javac String_demo.java
$ java String_demo
abc
356). What will be the output of the following Java program?
class String_demo
{
public static void main(String args[])
{
int ascii[] = { 65, 66, 67, 68};
String s = new String(ascii, 1, 3);
System.out.println(s);
}
}
[A]ABC
[B]BCD
[C]CDA
[D]ABCD
Show Answer
Correct Answer: BCD
Notes:
Answer: b
Explanation: ascii is an array of integers which contains ascii codes of Characters A, B, C, D. String(ascii, 1, 3) is an constructor which initializes s with Characters corresponding to ascii codes stored in array ascii, starting position being given by 1 & ending position by 3, Thus s stores BCD.
output:
$ javac String_demo.java
$ java String_demo
BCD
357). What will be the output of the following Java program?
class String_demo
{
public static void main(String args[])
{
char chars[] = {'a', 'b', 'c'};
String s = new String(chars);
String s1 = "abcd";
int len1 = s1.length();
int len2 = s.length();
System.out.println(len1 + " " + len2);
}
}
[A] 3 0
[B]0 3
[C]3 4
[D] 4 3
Show Answer
Correct Answer: 4 3
Notes:
Answer: d
Explanation: None.
output:
$ javac String_demo.java
$ java String_demo
4 3