Object Oriented Programming - I (3140705) MCQs

MCQs of Exception Handling, I/O, abstract classes and interfaces

Showing 31 to 38 out of 38 Questions
31.
What will be the output of the following Java program?
    interface calculate
    {
        void cal(int item);
    }
    class display implements calculate
    {
        int x;
        public void cal(int item)
        {
            x = item * item;            
        }
    }
    class interfaces
    {
        public static void main(String args[])
        {
            display arr = new display;
            arr.x = 0;      
            arr.cal(2);
            System.out.print(arr.x);
        }
    }
(a) 0
(b) 2
(c) 4
(d) None of the mentioned
Answer:

Option (c)

32.
Which of the following is the correct way of implementing an interface A by class B?
(a) class B extends A{}
(b) class B implements A{}
(c) class B imports A{}
(d) None of the mentioned
Answer:

Option (b)

33.
All methods must be implemented of an interface.
(a) TRUE
(b) FALSE
Answer:

Option (a)

34.
What type of variable can be defined in an interface?
(a) public static
(b) private final
(c) public final
(d) static final
Answer:

Option (d)

35.
What does an interface contain?
(a) Method definition
(b) Method declaration
(c) Method declaration and definition
(d) Method name
Answer:

Option (b)

36.
What type of methods an interface contain by default?
(a) abstract
(b) static
(c) final
(d) private
Answer:

Option (a)

37.
What will happen if we provide concrete implementation of method in interface?
(a) The concrete class implementing that method need not provide implementation of that method
(b) Runtime exception is thrown
(c) Compilation failure
(d) Method not found exception is thrown
Answer:

Option (c)

38.
What happens when a constructor is defined for an interface?
(a) Compilation failure
(b) Runtime Exception
(c) The interface compiles successfully
(d) The implementing class will throw exception
Answer:

Option (a)

Showing 31 to 38 out of 38 Questions