Bird
0
0

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

easy📝 Syntax Q12 of 15
Java - Object-Oriented Programming Concepts
Which of the following is the correct way to define a class in Java using OOP?
Aclass Car { int speed; void drive() { } }
Bprocedure Car { speed = 0; drive() }
Cfunction Car() { speed = 0; drive() }
Dobject Car = { speed: 0, drive: function() {} }
Step-by-Step Solution
Solution:
  1. Step 1: Identify Java class syntax

    Java classes are defined using the keyword 'class' followed by the class name and curly braces.
  2. Step 2: Check options for correct Java syntax

    class Car { int speed; void drive() { } } uses 'class' keyword and proper Java method and variable syntax.
  3. Final Answer:

    class Car { int speed; void drive() { } } -> Option A
  4. Quick Check:

    Java class syntax uses 'class' keyword [OK]
Quick Trick: Java classes start with 'class' keyword and curly braces [OK]
Common Mistakes:
  • Using 'procedure' or 'function' keywords which are not Java syntax
  • Using object literal syntax like JavaScript
  • Missing curly braces or semicolons

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes