Constructor is a non-static method having the same name as its class - Core Java

Q.  Which is a non-static method having the same name as its class?
- Published on 13 Jul 15

a. Field
b. Method
c. Constructor
d. None of the above

ANSWER: Constructor
 

    Discussion

  • Rupesh Bharuka   -Posted on 30 Sep 16
    Constructors are the special functions which has same name as of class name without any return type, not even 'void'

    Now somebody might be thinking why constructors are 'non-static' method?
    Because, constructors gets called when an object of that class is created. But static methods are such which we can call even before object creation. That's why constructors are always 'non-static'.

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)