Home > Cannot Be > Why Classes Cannot Be Protected Java

Why Classes Cannot Be Protected Java

Contents

so please enter the right answers and dontreply just for the sake of replying.Good Luck and Cheers

Was this answer useful?Yes Reply dipl. Forbidden.You don't have permission to view this page.https://www.quora.comPlease email [email protected] if you believe this is an error. We need to get Ldap user details using configured Ldap in weblogic server console. So protected can't use full potential(main scope is subclass-wide) in top-level which the outer is package(i.e. get redirected here

Overall, Java pick only package-private over protected to avoid confusing(it's just a matter of choice, but protected main characteristic is subclass, so package-private is superior), and the result, only 2 access Was this answer useful?Yes Reply Archana anbazhagan ProfileAnswers by Archana anbazhagan May 19th, 2008 no we cant declare class as protected Was this answer useful?Yes Reply manish Oct 17th, 2011 We cannot import it in this TestingIt.java file. How to handle a common misconception when writing a Master's thesis?

Why Class Cannot Be Private In Java

but found that the following worked: and not: I wanted...Asked by: anushree_123Problem with jsf / spring security 2.5Hello, First I would say sorry I dont speak English very well... There are only two valid declarations for a class at the namespace level, "Internal" and "Public". Hence it is not allowed. Medical Science Microbiology Biochemistry Biotechnology Biochemical Engineering Others General Knowledge Puzzles Quiz Sudoku Online Tests Ask your question?

Let's look at a collection of classes and see how access levels affect visibility. Straight line equation more hot questions question feed lang-java about us tour help blog chat data legal privacy policy work here advertising info mobile contact us feedback Technology Life / Arts sub-package, or package A extends package B, but we know no such thing. A Class Cannot Be Private Or Protected Except Nested Class What are Access Modifiers ?

It is not visible to a package outside home. Can A Class Be Private In Java and access GeekInterview anytime... What is Virtual Method Difference between class and object What is Data Encapsulation? Plase check for inner classes in java.sun.com.

It is valid for a nested type to be protected though: public class Foo { protected static class Bar{} } This allows subclasses of Foo to access Bar. Protected Class Java Example now making it visible outside the package (subclasses ) is bit confusing and tricky. The same misleading apply to pacakage-private, pacakage-private doesn't support subclass (N in cell) doesn't means subclass concept apply in outer. more hot questions question feed lang-java about us tour help blog chat data legal privacy policy work here advertising info mobile contact us feedback Technology Life / Arts Culture / Recreation

Can A Class Be Private In Java

Request timeout of servers while ping Advantages of static class over class ? Even if "protected class" was possible you would not be able to import it in another package just like a "default/no modifier class". Why Class Cannot Be Private In Java It is not visible to a package outside home. Can A Class Be Protected In C# If I say public, all classes in different package can use it which I do not want.

Try Compiling and Running the Examples: FAQs. Get More Info Strive to only make classes public if they really have to be. First, why would you want that? No , You can't declare a class as protected. A Class Cannot Be Private Or Protected In Java True Or False

posted 6 years ago Saibabaa Pragada wrote:I don't know if this is confusing. As you can see, a class always has access to its own members. Post Reply Bookmark Topic Watch Topic New Topic programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Languages Frameworks Products This Site Careers Other all forums Forum: Programmer Certification http://bovbjerg.net/cannot-be/what-does-int-cannot-be-dereferenced-mean-in-java.php Well, again, if you know what "protected" means then you should be able to figure out why you can't have a protected top-level class.

Types of power transmission Elements what is a derived table in data warehousing? A Class Cannot Be Private Or Protected True Or False public class OuterClass { protected class NestedClass { } }

Nested Class The .Net Framework allows you to define a class within another class. Only then can external entities (i.e.

Not the answer you're looking for?

What do you think? If it's the latter then let me know and I will move the thread to the right forum. How to reply? What Is The Difference Between An If Statement And A Switch Statement Saibabaa Pragada Ranch Hand Posts: 162 posted 6 years ago (1)&(2) Protected = within package accessibility + subclass(es) outside package.

If all the classes are allowed to subclass then it will be similar to public access specifier. asked 6 years ago viewed 28342 times active 29 days ago Upcoming Events 2016 Community Moderator Election ends Nov 22 Linked 32 How to protect classes so they are not visible and If all the classes are allowed to subclass then it will be similar to public access specifier." really helped me understand the problem as to why protected classes don't make this page Overall, Java pick only package-private over protected to avoid confusing(it's just a matter of choice, but protected main characteristic is subclass, so package-private is superior), and the result, only 2 access

If none then it is similar to Default. now making it visible outside the package (subclasses ) is bit confusing and tricky. But you haven't been focusing on that, you have been diverted by your peculiar requirement. Was this answer useful?Yes Reply Manish Kumar Singh Jul 16th, 2007 No we can't declare class protected because we know that when we declared class Protectecd then it's mean that

package office; import home. What are the different types of inheritance ? Access Levels Modifier Class Package Subclass World public Y Y Y Y protected Y Y Y N no modifier Y Y N N private Y N N N The first data share|improve this answer answered Apr 30 '13 at 5:50 akash746 8421013 "now making a protected class visible outside the package (subclasses ) is bit confusing and tricky.

What is nested class ? Since declaring a class as protected DOES give compilation error Was this answer useful?Yes Reply parthiba Mar 10th, 2006 D:\Tomcat5.0\webapps\servletproject\src>javac -d ../WEB-INF com/college/*.javacom/college/Hello.java:2: modifier protected not allowed hereprotected class Hello I'm not sure that it will ever be able to figure itself out, everything else, maybe. So If we are allowed to make a class protected then we can access it inside the package very easily but for accessing that class outside of the package we first

With inner classes you can define protected or static which is fine with me. Btw, why do you prefer default access more? Such class is called a nested class.