🎴 Flashcard Mode
Java Programming Fundamentals
Card1 / 10
Mastered0
Review0
QuestionClick to flip
Given: 1. public class A { 2. public void doit() { 3. } 4. public String doit() { 5. return “a”; 6. } 7. public double doit(int x) { 8. return 1.0; 9. } 10.} What is the result?
AnswerClick to flip back
A
Compilation fails because of an error in line 4.
💡 Explanation:
Java methods are distinguished by their signature (name and parameter types), not by return type. Lines 3 and 4 declare two doit() methods with identical signatures but different return types (void vs String), which causes compilation failure. Line 7 is valid overloading because the parameter differs.