Thursday 21 February 2013

14. What results from the following code?

14. What results from the following code?

Choices:
a. Line 4 will not compile as void methods can't be overridden.
b. An exception at line 9.
c. Line 9 will not compile as there is no version of myMethod which takes a char as argument.
d. The code compiles and produces output: int version.
e. The code compiles and produces output: String version.


Answer:-
D is correct.
A is incorrect as void methods can be overridden without any problem.
B is incorrect as char ch declaration is valid.
C is incorrect as char type in java is internally stored as integer and there is a method which takes int as an input.
D is correct, on line 9 char ch is widened to an int and passed to int version of the myMethod().
E is incorrect as int version of myMethod() is called.

No comments:

Post a Comment