Q: If the name of a class is "Computer", what will be the possible name of the constructor
-
A
computer()
-
B
COMPUTER()
-
C
Computer()
-
D
com()
C
Answer:
C
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()
Related Topic:
Share Above MCQ