MCQ
Single Best Answer
Moderate
Q
[Object Oriented Programming]
Which of the following is a valid prototype of the
non-parameterised constructor for the class Book?
Which of the following is a valid prototype of the non-parameterised constructor for the class Book?
ID: #24947
Competency focused Practice Questions ISC Class XII Computer Science
3 views
Question Info
#24947Q ID
ModerateDifficulty
Competency focused Practice Questions ISC Class XII Computer ScienceTopic
Your Answer
Choose the Best Option
Click any option to instantly check if you're correct.
Correct Answer: Option C
Explanation
[Object Oriented Programming]
Which of the following is a valid prototype of the non-parameterised constructor for the class Book?
Which of the following is a valid prototype of the non-parameterised constructor for the class Book?
Correct Answer: (c) public Book()
Understanding Constructor:
A constructor in Java is a special method that:
- Has the same name as the class
- Does NOT have any return type
- Is used to initialize objects
Non-Parameterized Constructor:
A non-parameterized constructor does not take any arguments.
public Book()
{
// constructor body
}
Important Rules:
- Constructor name must be same as class name → Book
- No return type (not even void)
- No parameters inside parentheses
Checking Each Option:
- (a) → This is a class declaration, not a constructor ❌
-
(b) → Using
voidmakes it invalid ❌ - (c) → Correct constructor syntax ✔
-
(d) → Constructor cannot have
void❌
Correct Constructor Example:
class Book
{
public Book()
{
System.out.println("Constructor called");
}
}
Conclusion:
The correct prototype of a non-parameterized constructor is:
public Book()
Therefore, the correct answer is: (c)
Continue Practice
Share
Share This Question
Challenge a friend or share with your study group.
More from This Topic