Bird
0
0

Which of the following is the correct way to declare a method in a Java class using OOP?

easy📝 Syntax Q3 of 15
Java - Object-Oriented Programming Concepts
Which of the following is the correct way to declare a method in a Java class using OOP?
Afunction display() { System.out.println("Hello"); }
Bvoid display() { System.out.println("Hello"); }
Cdef display() { System.out.println("Hello"); }
Dmethod display() { System.out.println("Hello"); }
Step-by-Step Solution
Solution:
  1. Step 1: Recall Java method syntax

    Java methods are declared with return type, name, parentheses, and body.
  2. Step 2: Identify correct syntax

    void display() { System.out.println("Hello"); } uses 'void' return type and proper Java syntax.
  3. Final Answer:

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

    Java method syntax = A [OK]
Quick Trick: Java methods start with return type, no 'function' keyword [OK]
Common Mistakes:
  • Using 'function' keyword like JavaScript
  • Using 'def' like Python
  • Using 'method' keyword which does not exist in Java

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes