🎴 Flashcard Mode
programming languages Online Quiz - 150
Card1 / 13
Mastered0
Review0
QuestionClick to flip
What results from the following code? 1. class MyClass 2. { 3. void myMethod(int i) {System.out.println("int version");} 4. void myMethod(String s) {System.out.println("String version");} 5. public static void main(String args[]) 6. { 7. MyClass obj = new MyClass(); 8. char ch = 'c'; 9. obj.myMethod(ch); 10. } 11. }
AnswerClick to flip back
A
The code compiles and produces output: int version.
💡 Explanation:
Java performs widening conversion from char to int when no exact method match exists. The primitive char type is promoted to int to match myMethod(int), not String, because String is an object reference type.