Method Overriding

POST TEST


Question 1:
What will be the output of the following Java program?
class Abc{
public static void main(String[]args){
String[] elements = { "for", "tea", "too" };
String first = (elements.length > 0) ? elements[0]: null;
}
}

Compilation error
An exception is thrown at run time.
The variable first is set to null.
The variable first is set to elements[0]


Question 2:
Which is runtime polymorphism in java oops?
Method overloading
Method overriding
The variable first is set to null
none of the above


Question 3
Which polymorphism concept is applied to inheritance relationship in java programming?
Method overloading.
Constructor overloading
Method overriding
None of above.


Question 4:
In below java program, the class Circle implements the interface Shape. Which polymorphism concept has been applied here?
interface Shape {
void area();
}
class Circle implements Shape {
public void area() {
}
}

Method overloading.
Constructor overloading
Method overriding
None of above.


Question 5:
Which method of base class X, the derived class Y cannon override?
class X {
final public void m1() {
}
public void m2() {

}

}
class Y extends X {

// override?
}

m1()
m2()
Both m1() and m2() can override
None of above


Question 6:
Which are true statements regarding polymorphism concept?
Method overloading is used in same class only
Constructor overloading is used in same class only
Method overriding is used in base class and derived class
ALL


Question 7:
What will be output?
class A{
static void method(){
system.out.println(" class A Method")
}
}
class B extendsA{
static void method(){
system.out.println(" class B Method")
}
}
public class Test{
public static void main(String args[]){
A a = new B();
a.method();
}
}

Class A method.
Class B method
Compilation Error
runtime Error


Number of score out of 7 = Score in percentage =