You are on page 1of 3

METHOD OVERLRIDING

1. What is the process of defining a method in a subclass having same name & type Answer: b
signature as a method in its superclass?
a) Method overloading c) Method hiding
b) Method overriding d) Method encapsulation
2. Which of these is supported by method overriding in Java? Answer: C
a) Abstraction c) Polymorphism
b) Encapsulation d) Inheritance
3. When the subclass method is intended as a replacement of the superclass method. Answer: A
a) Overriding c) Dependency
b) Extension d) Overloading
4. Which of this keyword can be used in a subclass to call the constructor of Answer: A
superclass?
a) super
b) this
c) extent
d) extends
5. What is the process of defining a method in a subclass having same name & type Answer: B
signature as a method in its superclass?
a) Method overloading
b) Method overriding
c) Method hiding
d) None of the mentioned
6. Which of these is supported by method overriding in Java? Answer: C
a) Abstraction
b) Encapsulation
c) Polymorphism
d) None of the mentioned
7. What will be the output of the following Java code? Answer: B
public class Person {
public void talk() {
System.out.print(“I am a Person”);
}
}

public class Student extends Person {


public void talk() {
System.out.print(“I am a Student”);
}
}

public class Test {


public static void main(String args[]) {
Person p = new Student();
p.talk();
}
}
A. I am a Person C. I am a Person I am a Student
B. I am a Student D. I am a Student I am a Person
8. What will be the output of the following Java code? Answer: B
class A {
private void printName() {
System.out.println(“Value-A”);
}
}

class B extends A {
private void printName() {
System.out.println(“Name-B”);
}
}

public class Test {


public static void main(String [] args) {
B b = new B();
b.printName();
}
}

A. Value-A B. Name-B C. Value-A Name-B D. Name-B Value-A


9. What is method overriding in Java? Answer: D
A. Writing a method in a subclass with the same name of superclass’s method.
B. Mentioning the same return type of the method of the superclass.
C. The argument list in the method of subclass and the method of superclass
should be the same.
D. All of these.
10. Whichof the following statements correctly overrides
the setQoh method?

A. C.
D.
B.

You might also like