how to make private class member private

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sun Mar 18 18:32:42 UTC 2018


On Sunday, March 18, 2018 18:04:13 Tony via Digitalmars-d-learn wrote:
> On Tuesday, 13 March 2018 at 06:03:11 UTC, Mike Parker wrote:
> > D is not C++, C#, or Java. C++ uses friend to get around the
> > issue. Java has no solution. I don't know about C#.
>
> Java has four protection levels. If you don't explicitly specify
> [private, protected, public] the protection level is implicitly
> "package-private". That means that any class in the same package
> can access that attribute. I believe that Java packages are
> identical to D packages.

They're similar, but there are differences. For instance, you can do
package(a) in D in order to do something like put the stuff in a.b.c in
package a rather than a.b. Also, package functions in D are never virtual,
which I expect is not the case for Java. The whole situation is also
complicated somewhat by the fact that D allows pretty much anything at
module-level, whereas as Java requires one class per module, though I'm not
sure that that has much direct effect on package itself other than the fact
that it's possible in D to mark stuff package that isn't in a class.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list