Sail E0 Webinar

MCQs

Total Questions : 26 | Page 1 of 3 pages
Question 1. Which of the following statement is correct?
  1.    replace() method replaces all occurrences of one character in invoking string with another character.
  2.    replace() method replaces only first occurances of a character in invoking string with another character.
  3.    replace() method replaces all the characters in invoking string with another character.
  4.    replace() replace() method replaces last occurrence of a character in invoking string with another character.
 Discuss Question
Answer: Option A. -> replace() method replaces all occurrences of one character in invoking string with another character.


replace() method replaces all occurrences of one character in invoking string with another character.


Question 2. Which of these class is used to create an object whose character sequence is mutable?
  1.    String()
  2.    StringBuffer()
  3.    Both of the mentioned
  4.    None of the mentioned
 Discuss Question
Answer: Option B. -> StringBuffer()


StringBuffer represents growable and writeable character sequence.


Question 3. Which of these method of class StringBuffer is used to find the length of current character sequence?
  1.    length()
  2.    Length()
  3.    capacity()
  4.    Capacity()
 Discuss Question
Answer: Option A. -> length()


length()


Question 4. Which of these method of class StringBuffer is used to concatenate the string representation to the end of invoking string?
  1.    concat()
  2.    append()
  3.    join()
  4.    concatenate()
 Discuss Question
Answer: Option B. -> append()


append()


Question 5.

What is the string contained in s after following lines of code?

 StringBuffer s new StringBuffer("Hello);

 s.deleteCharAt(0);

  1.    Hell
  2.    ello
  3.    Hel
  4.    llo
 Discuss Question
Answer: Option B. -> ello


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


Question 6. Which of these method of class String is used to obtain length of String object?
  1.    get()
  2.    Sizeof()
  3.    lengthof()
  4.    length()
 Discuss Question
Answer: Option D. -> length()


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


Question 7. Which of these class is superclass of String and StringBuffer class?
  1.    java.util
  2.    java.lang
  3.    ArrayList
  4.    None of the mentioned
 Discuss Question
Answer: Option B. -> java.lang


java.lang


Question 8. Which of these operators can be used to concatenate two or more String objects?
  1.    +
  2.    +=
  3.    &
  4.    ||
 Discuss Question
Answer: Option A. -> +


operator + is used to concatenate strings, Example String s = "i  + "like  + "java; String s contains "I like java.


Question 9. Which of these constructors is used to create an empty String object?
  1.    String()
  2.    String(void)
  3.    String(0)
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> String()


String()


Question 10. Which of these method of class String is used to extract a single character from a String object?
  1.    CHARAT()
  2.    charat()
  3.    charAt()
  4.    ChatAt()
 Discuss Question
Answer: Option C. -> charAt()


charAt()


Latest Videos

Latest Test Papers