Bird
0
0

Which of the following correctly defines a method named printHello that does not return any value and takes no arguments?

easy📝 Syntax Q3 of 15
Java - Methods and Code Reusability
Which of the following correctly defines a method named printHello that does not return any value and takes no arguments?
Aint printHello() { System.out.println("Hello"); }
Bvoid printHello() { System.out.println("Hello"); }
Cvoid printHello { System.out.println("Hello"); }
DprintHello() void { System.out.println("Hello"); }
Step-by-Step Solution
Solution:
  1. Step 1: Recall method syntax

    Method header includes return type, name, parentheses for parameters.
  2. Step 2: Check each option

    void printHello() { System.out.println("Hello"); } correctly uses 'void' return type, method name, parentheses, and braces.
  3. Final Answer:

    void printHello() { System.out.println("Hello"); } -> Option B
  4. Quick Check:

    Method syntax requires return type and parentheses [OK]
Quick Trick: Method must have return type and parentheses [OK]
Common Mistakes:
  • Omitting parentheses after method name
  • Using incorrect return type for void methods
  • Placing return type after method name

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes