What is the prototype of the default constructor?
public class Test { }
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.
Join The Discussion
Comments ( 2 )
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
In Java, which method is automatically called when an object is created?
A. start()
B. main()
C. init()
D. constructor()
What is method overloading in Java?
A. Defining multiple methods with the same name in the same class
B. Calling methods from another class
C. Using methods to load data from a file
D. Running methods in parallel threads
Even if class is defined public, default constructor need Not be defined as public.
Pls check.
You mentioned answer is option D.but while explaining answer you mention option D is wrong by mistakely.Please edit this.Thank you