Method Overloading and Method Overriding

Method Overloading and Method Overriding

13 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Which of the following statements is/are correct for static method in Java?

A. Static methods are always public.
B. Static method cannot access directly non-static method of the same class.

  1. Only A
  2. Only B
  3. Both A and B
  4. Neither A nor B
Question 2 Multiple Choice (Single Answer)

Which of the following statement(s) is/are correct?
A. valueOf() is a static method.
B. toString() is overridden in Integer and Double Class.

  1. Only A
  2. Only B
  3. Both A and B
  4. Neither A nor B
Question 3 Multiple Choice (Single Answer)

Which of the following conditions is incorrect for performing overriding of methods in Java?

  1. The method name in subclass must be identical to that of the superclass method.
  2. The return type of both the methods must be different.
  3. Methods of the superclass declared as public cannot be overrided using private keyword in the subclass.
  4. An overriding method cannot raise more exceptions than those raised by superclass.
  5. The overrided methods cannot have different number of arguments.
Question 4 Multiple Choice (Single Answer)

What is the most restrictive access modifier that will allow members of one class to have access to members of another class in the same package?

  1. public
  2. abstract
  3. protected
  4. synchronized
  5. default access
Question 5 Multiple Choice (Single Answer)

Which method is not overridden by Annotation interface?

  1. hashCode()
  2. equals()
  3. clone()
  4. toString()
Question 6 Multiple Choice (Single Answer)

Which two statements are true about properly overridden hashCode() and equals() methods?

  1. hashCode() doesn't have to be overridden if equals() is.
  2. equals() doesn't have to be overridden if hashCode() is.
  3. hashCode() can always return the same value, regardless of the object that invoked it.
  4. equals() can be true even if it's comparing different objects.
  1. 1 and 2
  2. 2 and 3
  3. 3 and 4
  4. 1 and 3
Question 7 Multiple Choice (Single Answer)

What is the difference between constructor and other methods?

  1. Constructor must not have the same name as the class name, whereas the methods can have any name.
  2. Constructor must have the same name as the class name whereas the methods can have any name.
  3. Constructor can have return type whereas the methods may or may not have return methods.
  4. Constructor and the methods can be called any number of times in the object life cycle.
Question 8 Multiple Choice (Single Answer)

Which of the following statements are correct?
i. final methods can be overridden
ii. final fields are constants
iii. final methods cannot be overridden
iv. final variables can be changed

  1. i and ii both are correct
  2. i and iv both are correct
  3. ii and iii both are correct
  4. ii and iii both are incorrect
Question 9 Multiple Choice (Single Answer)

Which of the following statements is/are correct?
:i. Overloaded methods are multiple methods which have the same name but different arguments.
ii. Overridden methods are multiple methods which have the same name, same return type and same arguments.
iii. Overloaded methods are multiple methods which have the same name, same return type and same arguments.
iv. Overridden methods are multiple methods which have the same name but different arguments.

  1. ii and iv are correct
  2. i and ii are correct
  3. only iii is correct
  4. only i is correct
Question 10 Multiple Choice (Single Answer)

Which of the following is/are true regarding overriding methods?
i. A method marked as final cannot be overridden.
ii. A method marked as static can be overridden.
iii. A method marked as final can be overridden.
iv. A method marked as static cannot be overridden.

  1. i and iv are correct
  2. only i is correct
  3. only ii is correct
  4. only iv is correct
Question 11 Multiple Choice (Single Answer)

Which of the following are true regarding dynamic method dispatch?
i. Dynamic method dispatch is a process in which a call to an overridden method is resolved at runtime rather than at compile time.
ii. Dynamic method dispatch is a process in which a call to an overridden method is resolved at compile time rather than at runtime.
iii. In Dynamic method dispatch process, a reference variable calls the overridden method of a superclass.
iv. In Dynamic method dispatch process, a reference variable calls the overridden method of a subclass.

  1. i. and iv. are correct
  2. i. and iii. are correct
  3. ii. and iii. are correct
  4. ii. and iv. are correct
Question 12 Multiple Choice (Single Answer)

Which of the following are true regarding super keyword?
i. Any level can be accessed using super keyword.
ii. In the constructor, if super() method is used, it should be the first code.
iii. Super is the keyword which is used to access method or member variables from the superclass.
iv. Super is the keyword which is used to access method or member variables from the subclass.

  1. i and ii both are correct
  2. ii and iii both are correct
  3. i and iv both are correct
  4. i and iii both are correct
Question 13 Multiple Choice (Single Answer)

Which of the following is true regarding overriding main method?
i. main method can be overridden because it is having access modifier as public.
ii. main method can be overridden because it is having return type as void.
iii. main method can be overridden because the method is static.
iv. main method cannot be overridden.

  1. Only i is correct
  2. Only ii is correct
  3. Only iii is correct
  4. Only iv is correct