SCJP Module-4 Question-13


 

SCJP Module-4 Question-13

The program given below tests your knowledge of method overloading in Java.

The program given below tests your knowledge of method overloading in Java.

Given below the sample code :

1. class Example13

2. {

3. void Method(int i) {System.out.println("int version");}

4. void Method(String s) {System.out.println("String version");}

5. public static void main(String args[])

6. {

7. Example13 obj = new Example13();

8. char ch = 'c';

9. obj.Method(ch);

10. }

11. }

What will be the output of the following ?

1. Error at Line 4 because void methods can't be overridden.
2  Error at line 9, an exception will be thrown.
3. Prints :  int version.
4. Prints : String version.

Answer :

(4)

Ads