Object Oriented Programming - I (3140705) MCQs

MCQs of Object oriented thinking

Showing 51 to 60 out of 64 Questions
51.
What will be the output of the following Java program?
    class output 
    {
        public static void main(String args[])
        {
            String a = "hello i love java";
            System.out.println(a.indexOf('e')+" "+a.indexOf('a')+" "+a.lastIndexOf('l')+" "+a.lastIndexOf('v'));
        }
    }
(a) 6 4 6 9
(b) 5 4 5 9
(c) 7 8 8 9
(d) 1 14 8 15
Answer:

Option (d)

52.
What will be the output of the following Java program?
    class output 
    {
        public static void main(String args[])
        { 
             StringBuffer c = new StringBuffer("Hello");
             StringBuffer c1 = new StringBuffer(" World");
             c.append(c1);
             System.out.println(c);
        }
    }
(a) Hello
(b) World
(c) Helloworld
(d) Hello World
Answer:

Option (d)

53.
What will be the output of the following Java code?
  class output 
  {  
      public static void main(String args[]) 
      {  
          StringBuffer sb=new StringBuffer("Hello");  
          sb.replace(1,3,"Java");  
          System.out.println(sb);
      }  
  }
(a) Hello java
(b) Hellojava
(c) HJavalo
(d) Hjava
Answer:

Option (c)

54.
What will be the output of the following Java code?
    class output 
    {
        public static void main(String args[])
        { 
           StringBuffer s1 = new StringBuffer("Hello");
           s1.setCharAt(1,'x');
           System.out.println(s1);
        }
    }
(a) xello
(b) xxxxx
(c) Hxllo
(d) Hexlo
Answer:

Option (c)

55.
What will be the output of the following Java code?
    class output 
    {
        public static void main(String args[])
        {
           StringBuffer s1 = new StringBuffer("Hello World");
           s1.insert(6 , "Good ");
           System.out.println(s1);
        }
   }
(a) HelloGoodWorld
(b) HellGoodoWorld
(c) HellGood oWorld
(d) Hello Good World
Answer:

Option (d)

56.
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);
        }
   }
(a) a
(b) b
(c) c
(d) abc
Answer:

Option (d)

57.
What will be the output of the following Java code?
    class output 
    {
        public static void main(String args[])
        { 
           String c = "Hello i love java";
           boolean var;
           var = c.startsWith("hello");
           System.out.println(var);
        }
    }
(a) TRUE
(b) FALSE
(c) 0
(d) 1
Answer:

Option (b)

58.
What will be the output of the following Java code?
    class output 
    {
        public static void main(String args[])
        { 
           String s1 = "Hello";
           String s2 = new String(s1);
           String s3 = "HELLO";
           System.out.println(s1.equals(s2) + " " + s2.equals(s3));
        }
    }
(a) true true
(b) false false
(c) true false
(d) false true
Answer:

Option (c)

59.
In the following Java code, which code fragment should be inserted at line 3 so that the output will be: “123abc 123abc”?
 1. StringBuilder sb1 = new StringBuilder("123");
 2. String s1 = "123";
 3.  // insert code here
 4. System.out.println(sb1 + " " + s1);
(a) sb1.append(“abc”); s1.append(“abc”);
(b) sb1.append(“abc”); s1.concat(“abc”);
(c) sb1.concat(“abc”); s1.append(“abc”);
(d) sb1.append(“abc”); s1 = s1.concat(“abc”);
Answer:

Option (d)

60.
What will be the output of the following Java code?
    class output 
    {
        public static void main(String args[])
        {
             String chars[] = {"a", "b", "c", "a", "c"};
             for (int i = 0; i < chars.length; ++i)
                 for (int j = i + 1; j < chars.length; ++j)
                     if(chars[i].compareTo(chars[j]) == 0)
                         System.out.print(chars[j]); 
        }
   }
(a) ab
(b) bc
(c) ca
(d) ac
Answer:

Option (d)

Showing 51 to 60 out of 64 Questions