Java MCQ's on Method Overloading
This test contains 10 questions based on Method Overloading.
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 for overloading a method in a class.
A.its return type should be same.
B.number of parameters it takes should be different.
C.type of parameters should be different.
Only A | Both A and B |
Either B and C | All of the above are true. |
Can we overload the constructor of a class ?
Yes | No |
What will happen if we try to overload the main method in a class.
Compile Time Error | Runtime Error |
main method gets overloaded | None Of these |
What will be the output of the following program ?
class Test{ public void test(){ System.out.print(" test1"); } private void test(String s1){ System.out.print(s1); this.test() ; } public static void main(String args[]){ System.out.print(" main"); Test obj = new Test(); obj.test(" test2"); } }
Compile Time Error | main test1 test2 |
main test2 test1 | None Of these |
What will be the output of the following program ?
class Test{ public int area(int a, int b){ System.out.println("int"); return a * b; } public float area(float a, float b){ System.out.println("float"); return a * b; } public double area(double a, double b){ System.out.println("double"); return a * b; } public static void main(String args[]){ Test obj = new Test(); obj.area(1, 2.2); obj.area(1F, 2.2); obj.area(1F, 2); } }
double float float | int double float |
int float double | double double float |
What will be the output of the following program ?
class Test{ public void test(int a){ System.out.println("int"); } public float test(float a){ System.out.println("float"); } public static void main(String args[]){ Test obj = new Test(); obj.test( 2.2 ); } }
Compile Time Error | Runtime Error |
int | float |
What will be the output of the following program ?
class Test{ public int test(int a){ System.out.println("test1"); return a; } public float test(int a){ System.out.println("test2"); return b; } public static void main(String args[]){ Test obj = new Test(); obj.test(2); } }
Compile Time Error | test1 |
test2 | test1 test2 |
What will be the output of the following program ?
class Test{ public static void main(String args){ System.out.println("main 1"); } public static void main(String args[]){ System.out.println("main 2"); } }
Compile Time Error | Runtime Error |
main 1 | main 2 |
What will be the output of the following program ?
class A{ public void test(){ System.out.println("testA "); } public void test(String args){ this.test(); System.out.println("testA "+ args); } } class B extends A{ public void test(){ System.out.println("testB "); } public static void main(String args[]){ A obj = new B(); obj.test("check"); } }
testA testB check | testA check testA |
testB testA check | Compile time error |
Finish Test
No comments: