wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Class accessibility Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Class accessibility" Watch "Class accessibility" New topic
Author

Class accessibility

nirjari patel
Ranch Hand

Joined: Apr 23, 2009
Posts: 371
This is theoritical question


package FirstAllAcessClasses;

protected class AccessInExtrendedClass{}

public class AccessInAnyClass{}

class AccessInThisPackage{}
------------------------------------------------------------------------
package FirstAllAcessClasses;

package TestAccessibility

public class ProtectedClassIsAccessed extends AccessInExtendedClass{}

protected class can be accessed in another package by a sub class. Public class can be accesses by any class and default class can not be accesses in another package.
-------------------------------------------------------------
import TestAccessibility;

package TestAccessibility2

public class AccessingAccessInExtendedClassWithoutExtending{}

---------------------------------------------------------------

Can we access protected class methods in AccessingAccessInExtendedClassWithoutExtending ? Or will this syntax allow even accessing methods of ProtectedClassIsAccessed{} ? Or will access restrictions cause error in compiling of AccessingAccessInExtendedClassWithoutExtending{} ?

Thanks

Thanks
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18553
    
  40

nirjari patel wrote:This is theoritical question




Is this a question about inner classes? Because there is no such a thing as a protected top-level class.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Class accessibility
 
Similar Threads
Access Specifiers - a Summary
Access Specifiers - a Summary
general question
Question on Protected
Confusing 'protected' behavior