This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Top level classes can be declared as public or they can be default. They can't be protected. Why is this so? When they can have default access modifier(friendly) which is more restricted than protected why can't they have their access modifier as protected? rajani
if a class 'x' of package 'p' has a default access modifier then there's no point having a protected method 'm' with 'x' because in another package we can't access class 'x' so how can we access 'm' .So my conclusion is that a class should be public(although not enforced by java) if its is declaring some protected members. please someone tell me if my conclusion is wrong.
A class needs to access within a package or outside it. So, default access will do for package access & public will do for outside package access. So, under what cicumstance would we need a protected modifer for?? Also, nasir, I do not agree with your view. Please have a loo at this and I hope u'll get clarified http://www.javaranch.com/ubb/Forum24/HTML/003727.html
- Sathvathsan Sampath
Joined: Nov 04, 2000
Thanks Sathvathsan you realy helped by giving me old post by sampaths77. What I extracted from that is Even a class 'x' has a default access modifier its public or protected members can be accssed by another class in another package if x extends a public class .