What, exactly, is data encapsulation? In java when I say that an advantage of nesting your classes is that it allows for data encapsulation...what exactly does that mean
I understand that it means hiding the internal state but I feel like I'm still flitting about somewhere close, but I'm not quite there yet. I would really appreciate it if somebody could explain this in non technical terms
It is just a phrase that describes treating that part of your code as a black box. For example, when you "encapsulate" a piece of data in a class, you can ignore whether it is implemented as an array or linked list or whatever. The implementation "under the hood" can be ignored, and you can do all the manipulations of that data you need with methods or other functions.
ok..so I think I'm beginning to get it. so if I have a block within a block...then the outer block isn't concerned with what's going on within the inner block
but does it follow that the inner block can see the other members of the outer block but the outer block can't see the members of the inner block
or does that depend entirely on the scope of the block?
What do you mean by "see?"
"access"? Does that make more sense?
Well that would seem to imply you mean the scope, so yeah if you understand the scoping of the variables then you understand which can access which. A function can access any variable within its scope.
Hey..wait...I think I got it. It's stated as clear as night and day over here ` https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html ` but I seemed to have been looking three blinkers...I completely overlooked it when it comes to classes and nested classes it has to do with the `static` modifier
Yeah, I'm not a Java guy, so I don't know how that whole static thing works unless it works the same as in C++. I'll have to let someone more qualified finish answering your question.
its ok, thanks, I got it, and your explanation helped...sometimes all it takes is a change in the wording
ok, glad I could contribute :)
Join our real-time social learning platform and learn together with your friends!