Object Oriented Programming - I (3140705) MCQs

MCQs of Object oriented thinking

Showing 61 to 64 out of 64 Questions
61.
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
Answer:

Option (c)

62.
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
Answer:

Option (d)

63.
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
Answer:

Option (a)

64.
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
Answer:

Option (c)

Showing 61 to 64 out of 64 Questions