Single Choice Easy

QIf the name of a class is "Computer", what will be the possible name of the constructor

ID: #22237 switch case in Java 112 views
Question Info
#22237Q ID
EasyDifficulty
switch case in JavaTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A computer()
  • B COMPUTER()
  • C Computer()
  • D com()
Correct Answer

Explanation

The name of a constructor in Java must match the name of the class exactly. Therefore, if the name of the class is Computer, the possible name of the constructor must be:

c) Computer()

Explanation:

  • Constructor Name: In Java, a constructor is a special method that is called when an instance of a class is created. The constructor must have the same name as the class and does not have a return type, not even void.

  • Options:

    • a) computer(): Not correct because the constructor name should match the class name exactly, including case.
    • b) COMPUTER(): Not correct because Java is case-sensitive, and the constructor name must match the class name exactly.
    • c) Computer(): Correct, as it matches the class name exactly.
    • d) com(): Not correct because it does not match the class name.

Correct Answer:

c) Computer()

Share This Question

Challenge a friend or share with your study group.