public class MyClass{ }
For the above class(MyClass) what is the correct way of declaring constructor?
public class MyClass{ }
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.
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
Join The Discussion