Java Programming - Declarations and Access Control - Discussion

Discussion Forum : Declarations and Access Control - General Questions (Q.No. 5)
5.
public class Test { }
What is the prototype of the default constructor?
Test( )
Test(void)
public Test( )
public Test(void)
Answer: Option
Explanation:

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 D 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.

Discussion:
13 comments Page 2 of 2.

Soumik Sarkar said:   4 years ago
In the above example, Outer () is a non-parameterised constructor. Not a default constructor. We can not initialize the default constructor. It will automatically initialize by the compiler itself when we can not define a constructor in a class.

Soumyaranjan Rout said:   3 years ago
As you said, the default constructor has the same access modifier as the class.

If a class is declared as final then what will be the access modifier of the default constructor.

Soumyaranjan Rout said:   3 years ago
As you said, the default constructor has the same access modifier as the class.

If a class is declared as final, what will be the access modifier of the default constructor.


Post your comments here:

Your comments will be displayed after verification.