- mark the method "public"
- Right here, you know this one is wrong. Public is accessible by all methods in all packages.
- mark the method "package"
- This isn't even a modifier that exists. So pass. One might be temted by this answer and it is meant to throw you. Know your Java access modifiers.
- mark the method "protected"
- Well this is closer to restriction and in a sense true, however, protected is accessible by the class only and the subclasses of the class.
- do not mark the method with a modifier
- Otherwise known as default. This is the answer we're looking for. Providing no modifier makes the method accessible throughout the same package only.
As with the other technical interview articles, these are meant to be a quick reference for an answer rather than a tutorial on use.
0 comments:
Post a Comment