OCA Java SE 8 Method - OCA Mock Question Method 6
Question
Which of the following are true?
- You can call this() from anywhere in a constructor.
- You can call this() from any instance method in the class.
- You can call this.variableName from instance method in the class.
- You can call this.variableName from static method in the class.
- You can call the default constructor added by the compiler using this().
- You can access a private constructor inside the main() method.
Answer
Note
this() can be called in the instance constructor as the first statement provided that a constructor
without parameter is defined.
We can access the private constructor within the same class from main method.