Examveda
Examveda

What is the prototype of the default constructor?
public class Test { }

A. public Test(void)

B. Test( )

C. Test(void)

D. public Test( )

E. None of these

Answer: Option D

Solution(By Examveda Team)

Option A and B are wrong because they use the default access modifier and the access modifier for the class is public (remember, the default constructor has the same access modifier as the class).

Option C is wrong. The void makes the compiler think that this is a method specification - in fact if it were a method specification the compiler would spit it out.


This Question Belongs to Java Program >> Constructors And Methods

Join The Discussion

Comments ( 2 )

  1. Santosh Kabir
    Santosh Kabir :
    4 years ago

    Even if class is defined public, default constructor need Not be defined as public.
    Pls check.

  2. Vinothini K
    Vinothini K :
    6 years ago

    You mentioned answer is option D.but while explaining answer you mention option D is wrong by mistakely.Please edit this.Thank you

Related Questions on Constructors and Methods

What is a constructor in Java?

A. A special method to create instances of classes

B. A method used for mathematical calculations

C. A method to perform string manipulations

D. An exception handling mechanism