Object Oriented Programming - I (3140705) MCQs

MCQs of Object oriented thinking

Showing 41 to 50 out of 64 Questions
41.
Which of these data type value is returned by equals() method of String class?
(a) char
(b) int
(c) boolean
(d) all of the mentioned
Answer:

Option (c)

42.
Which of these method of class String is used to remove leading and trailing whitespaces?
(a) startsWith()
(b) trim()
(c) Trim()
(d) doTrim()
Answer:

Option (b)

43.
What is the value returned by function compareTo() if the invoking string is greater than the string compared?
(a) zero
(b) value less than zero
(c) value greater than zero
(d) none of the mentioned
Answer:

Option (c)

44.
At line number 2 in the following code, choose 3 valid data-type attributes/qualifiers among “final, static, native, public, private, abstract, protected”
1. public interface Status
2.   {
3.        /* insert qualifier here */ int MY_VALUE = 10;
4.   }
(a) final, native, private
(b) final, static, protected
(c) final, private, abstract
(d) final, static, public
Answer:

Option (d)

45.
What will be the output of the following Java program?
   final class A 
    {
         int i;
    }    
    class B extends A 
    {
        int j;
        System.out.println(j + " " + i);  
    }    
    class inheritance 
    {
        public static void main(String args[])
        {
            B obj = new B();
            obj.display();     
        }
   }
(a) 2 2
(b) 3 3
(c) Runtime Error
(d) Compilation Error
Answer:

Option (d)

46.
What will be the output of the following Java program?
    class A 
    {
        int i;
        public void display() 
        {
            System.out.println(i);
        }    
    }    
    class B extends A 
   {
        int j;
        public void display() 
        {
            System.out.println(j);
        } 
    }    
    class Dynamic_dispatch 
   {
        public static void main(String args[])
        {
            B obj2 = new B();
            obj2.i = 1;
            obj2.j = 2;
            A r;
            r = obj2;
            r.display();     
        }
   }
(a) 1
(b) 2
(c) 3
(d) 4
Answer:

Option (b)

47.
What will be the output of the following Java program?
    class A 
    {
        int i;
        void display() 
        {
            System.out.println(i);
        }
    }    
    class B extends A 
    {
        int j;
        void display() 
        {
            System.out.println(j);
        }
    }    
    class inheritance_demo 
    {
        public static void main(String args[])
        {
            B obj = new B();
            obj.i=1;
            obj.j=2;   
            obj.display();     
        }
   }
(a) 0
(b) 1
(c) 2
(d) Compilation Error
Answer:

Option (c)

48.
What will be the output of the following Java program?
    class A 
    {
        int i;
    }    
    class B extends A 
    {
        int j;
        void display() 
        {
            super.i = j + 1;
            System.out.println(j + " " + i);
        }
    }    
    class inheritance 
    {
        public static void main(String args[])
        {
            B obj = new B();
            obj.i=1;
            obj.j=2;   
            obj.display();     
        }
   }
(a) 2 2
(b) 3 3
(c) 2 3
(d) 3 2
Answer:

Option (c)

49.
What will be the output of the following Java program?
    class A 
    {
        public int i;
        public int j;
        A() 
        {
            i = 1;
            j = 2;
	}
    }    
    class B extends A 
    {
        int a;
        B() 
        {
            super();
        } 
    }    
    class super_use 
    {
        public static void main(String args[])
        {
            B obj = new B();
            System.out.println(obj.i + " " + obj.j)     
        }
   }
(a) 1 2
(b) 2 1
(c) Runtime Error
(d) Compilation Error
Answer:

Option (a)

50.
What will be the output of the following Java code?
    class A 
    {
        public int i;
        private int j;
    }    
    class B extends A 
    {
        void display() 
        {
            super.j = super.i + 1;
            System.out.println(super.i + " " + super.j);
        }
    }    
    class inheritance 
   {
        public static void main(String args[])
        {
            B obj = new B();
            obj.i=1;
            obj.j=2;   
            obj.display();     
        }
   }
(a) 2 2
(b) 3 3
(c) Runtime Error
(d) Compilation Error
Answer:

Option (d)

Showing 41 to 50 out of 64 Questions