Ellen Bee wrote:If I understand correctly you can access a private constructor from anywhere in the same class, not only the main() method.
True! Any private constructor and/or method can be accessed/invoked from any code in the same class. (And that's why option G is correct
)
Ellen Bee wrote:Furthermore the main() method can as well be in another class (probably will be, because any non-trivial application will have multiple classes), in that case you can't access the private constructor from the main() method.
If the
main() method is defined in
ClassX, you can't access a private constructor and/or method of
ClassY, even if both classes are defined in the same source code file. As illustrated in this code snippet
Ellen Bee wrote:I have some difficulties understanding why option G is correct at all.
Because it's a
true statement
As mentioned earlier, you can access a private constructor from the
main() method. You could (and probably would) argue that if the
main() method is defined in another class you would not be able to access the private constructor. And that's true as well, but
with this reasoning you are completely ignoring the
"context of a question". None of the options mentions something like "another class", "two classes",... so that means that every statement is about only one class. And if you only have one class with a
main() method, you can access its private constructor (so option G is correct). In
this thread you'll find a nice discussion about this
"context of a question", it's definitely worth reading.
On the actual exam you know for each question how many correct answers you have to select. That's really helpful! Because you know how many answers to select, so if you have 1 obvious answer but the question states to select 2 you know you need to select another one (which you otherwise probably not would have selected). When
I took the OCA7 exam, I even had to select an answer with a compiler error because all other answers were definitely incorrect!
Hope it helps!
Kind regards,
Roel