Home > Cannot Be > Why Classes Cannot Be Protected Java

Why Classes Cannot Be Protected Java

Contents

But a top-level class isn't a member of any class. –Jon Skeet Feb 13 '15 at 7:01 add a comment| up vote 2 down vote protected or private class has no Can an object *immediately* start moving at a high velocity? Do we know Ford's old name? Browse other questions tagged java class protected or ask your own question.

So if "private class foo"(A private member defined, i.e. vamsi acharya Ranch Hand Posts: 55 I like... Object Based Language and OOPs Share .Net Environment - Interview Questions ADO.Net - Interview Questions .Net Framework - Interview Questions .Net General - Interview Questions Asp.Net - Interview Questions Object I want to give access only to subclasses in different package which can extends base class(protected access).

Why Class Cannot Be Private In Java

File scope ? A sub-class can't have the same method signature with a different implementation.I don't want my class to be inherited by any other class. If I say public, all classes in different package can use it which I do not want.

But nested private class is allow because the direct outer is class, not package, e.g.: class PrivateNestedMain { private static class Inner { public static void main(String[] args) { System.out.println("Hello from Asked by: Vinod G SServlet intialization parameterHow we can define Servlet Initalization Parameter?Asked by: akash_butaniGetting ldap user details from weblogic portal configurationHow to Get Ldap user details from weblogic portal configuration? now making it visible outside the package (subclasses ) is bit confusing and tricky. A Class Cannot Be Private Or Protected Except Nested Class So if you have a class which tried to extend a Class which is visible within the package- Then I would say that one has to check the design.

For example you have the class:as DefaultClass.java package home; class DefaultClass{ .. } and another class as TestingIt.java in another package. Can A Class Be Private In Java package office; import home. Saibabaa Pragada Ranch Hand Posts: 162 posted 6 years ago Hi, I am wondering why a class(outer class) cannot be defined as protected and/or static ? In a nutshell, my question is Why base class cannot be protected or static.

But for subclass, visibility of parent “protected”class would be private. Protected Class Java Example 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. How to stop NPCs from picking up dropped items Forcing everyone to speak the same language Can you dispel a magic effect you can't perceive? Asked by: RATNAPRABHADifference between include directive and script tag while including Java scripts file in JSP.I was trying to use JavaScript file for validations of the fields and buttons in my

Can A Class Be Private In Java

Hence, as far as access modifiers for classes are concerned both protected and default are the same. A class may be declared with the modifier public, in which case that class is visible to all classes everywhere. Why Class Cannot Be Private In Java So protected can't use full potential(main scope is subclass-wide) in top-level which the outer is package(i.e. Can A Class Be Protected In C# Since there's no such concept as 'subpackage' or 'package-inheritance' in Java, declaring class protected or package-private would be the same thing.

Strive to only make classes public if they really have to be. Next:Can we declare private class in namespace What is a Class? Not the answer you're looking for? And since a package can not be extended (can be imported), defining a class protected will again make it package-private which is similar to defining it as default which we can A Class Cannot Be Private Or Protected In Java True Or False

so why can't we suppose to use it.. –Santhosh Sep 14 '10 at 7:27 @santose: Protected is only visible to the children of that class. Was this answer useful?Yes Reply prakash Mar 18th, 2013 Class can be protected or private but only inner Was this answer useful?Yes Reply Raghunath Aug 16th, 2013 A class GO OUT AND VOTE My cat sat on my laptop, now the right side of my keyboard types the wrong characters TSA broke a lock for which they have a master Hence, as far as access modifiers for classes are concerned both protected and default are the same.

But for subclass, visibility of parent “protected”class would be private. A Class Cannot Be Private Or Protected True Or False Why hippopotamus instead of potamohippus? How to handle a common misconception when writing a Master's thesis?

But you haven't been focusing on that, you have been diverted by your peculiar requirement.

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 There would be some classes which can be used by other packages so they would be Public. Paul Clapham Sheriff Posts: 21444 33 I like... What Is The Difference Between An If Statement And A Switch Statement As usually we keep related classes together.

If so, which Constructor executes first (Sub Class OR Super Class) for the...Asked by: Lekha/SreelekhaRead the following code and then implement the following parts:Read the following code and then implement the more stack exchange communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour Start here for a quick overview of the site Help Center Detailed I should have said "which is a very simple concept" to make it more clear (because I think beginners would probably find public modifier to be the simplest to learn). If you try to access from a outter class in other package this protected method member is not visible. –kelgwiin Jun 17 '15 at 13:59 add a comment| up vote 11

current community chat Stack Overflow Meta Stack Overflow your communities Sign up or log in to customize your list. 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 Second, when you write a class, you need to decide what access level every member variable and every method in your class should have. 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

Can an object *immediately* start moving at a high velocity? What should i do?You should declared your class as final. because default = limited to its own package. And now coming to your question "why cant a class have protected access-modifier?" I think its probably because it would be no different than a default/no modifier class.

suhaib mustafa Greenhorn Posts: 10 posted 4 years ago I will try to answer this question in simple terms. We cannot import it in this TestingIt.java file. Solving a discrete equation Does the Rothschild family own most central banks? The moment you try to import home.DefaultClass in the above code you will realize that our DefaultClass cannot be imported.

Abstract class and final class Sub class method call Read the following code and then implement the following parts: JDBC ODBC class name Telecom - equivalence class portioning Why abstract class up vote 22 down vote favorite 8 I know this is a stupid question, but still i have a doubt which needs to be cleared. Mohamed Sanaulla Saloon Keeper Posts: 3165 34 I like... if you don't mention any access specifier by default it will take class as default access specifier Was this answer useful?Yes Reply narendra Mar 6th, 2006 we can declare