• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class accessibility

 
nirjari patel
Ranch Hand
Posts: 386
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21490
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic