Java MCQ's on Method Overriding
This test contains 10 questions based on Method Overriding.
Each question answered correctly awards you 1 point and each incorrect answer has a penalty of -0.25 points, no points are deducted for unattempted answers.
Each question answered correctly awards you 1 point and each incorrect answer has a penalty of -0.25 points, no points are deducted for unattempted answers.
Select Test Type
You Get +1 for each correct answer and -0.25 for each incorrect answer
Time Left -
minutes
:
seconds
Compile time polymorphism is also known as
Method Overriding | Method Overloading |
Method Rewriting | None of these |
Which conditions should a method satisfy to override a method of parent class.
A.its return type should be same.
B.number of parameters it takes should be same and of same type.
C.its access specifier should not be weaker than the method to be overloaded.
Only A | Only B |
Both A and B | All of the above are true. |
What happens if we override static methods of a class.
Compile time error | Run time error |
No error is thrown | None of these |
What will be the output of the following program.
class A{ static void t(){} } class B extends A{ public void t(){} }
Compile Time Error | Runtime Error |
Code works fine | None Of these |
What will be the output of the following program ?
class A{ static void t(){} } class B extends A{ static void t(){} }
Compile Time Error | Runtime Error |
Code works fine | None Of these |
What will be the output of the following program ?
class A{ public void test(){ System.out.println("Class A"); } } class B extends A{ public void test(){ System.out.println("Class B"); } public static void main(String args[]){ A object = new B(); object.test(); } }
Compile Time Error | Runtime Error |
Class A | Class B |
What will be the output of the following program ?
class A{ public void test(){ System.out.println("Class A"); } } class B extends A{ public void test(){ System.out.println("Class B"); } public static void main(String args[]){ B object = new A(); object.test(); } }
Compile Time Error | Runtime Error |
Class A | Class B |
What will be the output of the following program ?
class A{ public void test(){ System.out.println("Class A"); } } class B extends A{ public void test(){ System.out.println("Class B"); } public static void main(String args[]){ B object = (B)new A(); object.test(); } }
Compile Time Error | Runtime Error |
Class A | Class B |
What will be the output of the following program ?
class A{ public void test(){ System.out.println("Class A"); } } class B extends A{ void test(){ System.out.println("Class B"); } public static void main(String args[]){ A object = new B(); object.test(); } }
Compile Time Error | Runtime Error |
Class A | Class B |
What will be the output of the following program ?
class A{ int var = 10; public void test(){ System.out.println("Class A"); } } class B extends A{ int var = 20; public void test(){ System.out.println("Class B"); } public static void main(String args[]){ A object = new B(); object.test(); System.out.println(object.var); } }
Class A 10 | Class B 10 |
Class A 20 | Class B 20 |
Finish Test
No comments: