Sail E0 Webinar

MCQs

Total Questions : 19 | Page 2 of 2 pages
Question 11. String str1 = "Kolkata".replace('k', 'a');
In the above statement, the effect on string Kolkata is
  1.    The first occurrence of k is replaced by a.
  2.    All characters k are replaced by a.
  3.    All characters a are replaced by k.
  4.    Displays error message
 Discuss Question
Answer: Option B. -> All characters k are replaced by a.
Question 12. The class string belongs to ................. package.
  1.    java.awt
  2.    java.lang
  3.    java.applet
  4.    java.string
 Discuss Question
Answer: Option B. -> java.lang
Question 13. What will be the output?
public class Test{
public static void main (String[] args){
String test = "a1b2c3";
String[] tokens = test.split("\\d");
for(String s: tokens)
System.out.print(s);
}
}
  1.    abc
  2.    123
  3.    Runtime exception thrown
  4.    Compilation error
 Discuss Question
Answer: Option A. -> abc
Question 14. How many Constructor String class have?
  1.    2
  2.    7
  3.    13
  4.    11
  5.    None of this
 Discuss Question
Answer: Option C. -> 13
Question 15. How many objects will be created?
String a = new String("Examveda");
String b = new String("Examveda");
String c = "Examveda";
String d = "Examveda";
  1.    4
  2.    3
  3.    2
  4.    None of this
 Discuss Question
Answer: Option B. -> 3
Question 16. What will be output?
String S1 = "S1 ="+ "123"+"456";
String S2 = "S2 ="+(123+456);
  1.    S1=123456, S2=579
  2.    S1=123456,S2=123456
  3.    S1=579,S2=579
  4.    None of This
 Discuss Question
Answer: Option A. -> S1=123456, S2=579
Question 17. What will be the output of the following program code?
public class Test{
public static void main(String args[]){
String s = "what";
StringBuffer sb = new StringBuffer("what");
System.out.print(sb.equals(s)+","+s.equals(sb));
}
}
  1.    true,true
  2.    false,true
  3.    true,false
  4.    false,false
  5.    None of these
 Discuss Question
Answer: Option D. -> false,false
Question 18. What will be the output?
1. public class Test{
2. public static void main(String args[]){
3. Object myObj = new String[]{"one", "two", "three"};
4. {
5. for(String s : (String[])myObj)
6. System.out.print(s + ".");
7. }
8. }
9. }
  1.    one.two.three.
  2.    Compilation fails because of an error at line 3
  3.    Compilation fails because of an error at line 5
  4.    An exception is thrown at runtime.
  5.    None of these
 Discuss Question
Answer: Option A. -> one.two.three.
Question 19. Determine output:
public class Test{
public static void main(String args[]){
String str = null;
if(str.length() == 0){
System.out.print("1");
}
else if(str == null){
System.out.print("2");
}
else{
System.out.print("3");
}
}
}
  1.    Compilation fails.
  2.    "1" is printed.
  3.    "2" is printed.
  4.    "3" is printed.
  5.    An exception is thrown at runtime.
 Discuss Question
Answer: Option E. -> An exception is thrown at runtime.

Latest Videos

Latest Test Papers