Re: Understanding class access



On May 31, 9:33 am, André Wagner <andre....@xxxxxxxxx> wrote:
Hello,

let's say I'm writing a extension organized in packages such as:

mycompany.mypackage.MyClass
mycompany.mypackage.subpackage.MySubClass

The people who are going to use my extension will extend MyClass. So I
declare it to be public.

But I don't want people to be able to access MySubClass, so I can't
declare as public. But I want MyClass to be able to access MySubClass,
and if I don't declare MySubClass to be public, the compiler complains
that MySubClass is in a different package and must be public.

(I hope I'm being clear here :-)

Is there anyway that I can access MySubClass from MyClass, but make
MySubClass invisible for packages outside mycompany.mypackage?

Thank you in advance,

André

If you don't want MySubClass to be subclassed, declare it final --
that's what it's there for.

.



Relevant Pages

  • Re: Understanding class access
    ... The people who are going to use my extension will extend MyClass. ... declare it to be public. ... But I want MyClass to be able to access MySubClass, ... MySubClass invisible for packages outside mycompany.mypackage? ...
    (comp.lang.java.programmer)
  • Understanding class access
    ... The people who are going to use my extension will extend MyClass. ... declare it to be public. ... But I want MyClass to be able to access MySubClass, ... MySubClass invisible for packages outside mycompany.mypackage? ...
    (comp.lang.java.programmer)
  • nested classes, OOP
    ... Is there a way to implement nested classes in MATLAB? ... if I have two separate classes "myClass" and ... function = mySubClass() ... but this violates the philosophy of encapsulation. ...
    (comp.soft-sys.matlab)
  • Help! Reflection object target in c#?
    ... public class MySubClass ... public String Text ... public class MyClass ... private MySubClass obj_MySubClass=new MySubClass; ...
    (microsoft.public.dotnet.framework)
  • Re: How to call the subclasss method?
    ... If the method is unique to the subclass you may not want it virtual as other ... > I created a class "myClass" and another class "mySubclass" which inherited ... > but I got an error message when I tried to compile it: ...
    (microsoft.public.dotnet.languages.csharp)