This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
In whizlabs demo tests one of the que goes In java a "protected" variable is more accesible than a default variable (variable with no access modifier) true false I chose true still it gave me wrong Seems like cant trust these commercial packages.
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
Yogesh, You probably just misread the problem. Default member variables will be accessible from all classes in the same package and all subclasses. Protected variables will be accessibly only from subclasses. So, protected variables are less accessible than default variables, not more accessible--thus the false answer.
I think "protected" can be accessed from 1.all members in the same package 2.or by subclasses of the class in which it is declared and "default" can be accesses from 1.all members in the same package. So protected wins by one point
Joined: May 29, 2003
Yogesh, Protected members can ONLY be accessible from subclasses. You can check out the language specification to see for yourself. To correct my last post: default members will be accessible from any class in the same package, but no subclasses defined outside the package in question. Protected members are still, as in my last post, only accessible to the current class and its subclasses.
Nathaniel, I thought the way this worked is that protected members can be accessed in all cases where default members can be accessed (when the accessing member belongs to the same package) AND via a subclass through inheritance. From the language specification, a few lines above where you linked: ... if the member or constructor is declared protected, then access is permitted only when one of the following is true: - Access to the member or constructor occurs from within the package containing the class in which the protected member or constructor is declared. - Access is correct as described in �6.6.2.
Joined: May 29, 2003
Ed, You're right -- I'm wrong. I'm suddenly amazed I passed the SCJP exam at all. So, the original question should be answered true, and the Whizlab is incorrect. It took me all of 30 seconds with NetBeans to convince myself. Now to delete my posts and pretend this never happened!