Examveda
Examveda

public class MyClass{ }

For the above class(MyClass) what is the correct way of declaring constructor?

A. MyClass(){}

B. MyClass(void) {}

C. public MyClass(){}

D. public MyClass(void){}

E. 1 and 3

Answer: Option E

Solution(By Examveda Team)

Choice A,C are the correct answers.
The default access specifier for any constructor is same as the access specifier of class.so the options A and C are correct.


This Question Belongs to Java Program >> Constructors And Methods

Join The Discussion

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