378). What will s2 contain after following lines of Java code?
 String s1 = "one";
String s2 = s1.concat("two")

[A]one
[B]two
[C]onetwo
[D]twoone

Show Answer

380). What is the value returned by function compareTo() if the invoking string is greater than the string compared?
 String s1 = "one";
String s2 = s1.concat("two")

[A]zero
[B]value less than zero
[C]value greater than zero
[D] none of the mentioned

Show Answer

381). Which of the following statement is correct?
 String s1 = "one";
String s2 = s1.concat("two")

[A]replace() method replaces all occurrences of one character in invoking string with another character
[B]replace() method replaces only first occurrences of a character in invoking string with another character
[C]replace() method replaces all the characters in invoking string with another character
[D]replace() replace() method replaces last occurrence of a character in invoking string with another character

Show Answer

382). What will be the output of the following Java 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

Show Answer

383). What will be the output of the following Java 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

Show Answer

384). What will be the output of the following Java program?
    class output 
    {
        public static void main(String args[])
        { 
           String s1 = "Hello";
           String s2 = s1.replace('l','w');
           System.out.println(s2);
        }
    }

[A]hello
[B]helwo
[C]hewlo
[D]hewwo

Show Answer

385). What will be the output of the following Java program?
    class output 
    {
        public static void main(String args[])
        {
           String s1 = "Hello World";
           String s2 = s1.substring(0 , 4);
           System.out.println(s2);
        }
   }

[A]Hell
[B]Hello
[C]Worl
[D]World

Show Answer

386). What will be the output of the following Java program?
    class output 
    {
        public static void main(String args[])
        {             String s = "Hello World";
             int i = s.indexOf('o');
             int j = s.lastIndexOf('l');
             System.out.print(i + " " + j);
 
        }
   }

[A]4 8
[B]5 9
[C]4 9
[D]5 8

Show Answer