arrow
arrow
arrow
Which of the following should have the same name as the class name?
Question



Which of the following should have the same name as the class name?

A.

Variable

B.

Method

C.

Constructor

D.

Header File

Correct option is C

A constructor is a special type of method in object-oriented programming that has the same name as the class. Its primary purpose is to initialize objects of the class when they are created.
Important Key Points:
1. Constructors are automatically invoked when an object is instantiated.
2. They do not have a return type, not even void.
3. Constructors can be default (no parameters) or parameterized (accept parameters to initialize fields).
Knowledge Booster:
· Variable: Can have any valid name and does not need to match the class name.
· Method: General functions within a class; their names are not required to match the class name.
· Header File: A separate file in C/C++ containing declarations, unrelated to constructors or class naming.

Free Tests

Free
Must Attempt

Unit & Measurement - 1

languageIcon English
  • pdpQsnIcon10 Questions
  • pdpsheetsIcon10 Marks
  • timerIcon5 Mins
languageIcon English
Free
Must Attempt

States of Matter

languageIcon English
  • pdpQsnIcon10 Questions
  • pdpsheetsIcon10 Marks
  • timerIcon5 Mins
languageIcon English
Free
Must Attempt

Classification of Plants

languageIcon English
  • pdpQsnIcon10 Questions
  • pdpsheetsIcon10 Marks
  • timerIcon5 Mins
languageIcon English
test-prime-package

Access ‘UPSSSC JE’ Mock Tests with

  • 60000+ Mocks and Previous Year Papers
  • Unlimited Re-Attempts
  • Personalised Report Card
  • 500% Refund on Final Selection
  • Largest Community
students-icon
353k+ students have already unlocked exclusive benefits with Test Prime!
Our Plans
Monthsup-arrow