hamburger menu
All Coursesall course arrow
adda247
reward-icon
adda247
    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

    Government Policies and Scheme

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

    Government Schemes

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

    SSC GD PYP (Held on 4 Feb 2025 S1)

    languageIcon English
    • pdpQsnIcon80 Questions
    • pdpsheetsIcon160 Marks
    • timerIcon60 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
    368k+ students have already unlocked exclusive benefits with Test Prime!
    Our Plans
    Monthsup-arrow