+ 1

What's the difference between "void" and "encapsulation"?

It's probably in its purpose but I'm still not sure what the difference is.

21st Aug 2017, 2:18 PM
Bhekumusicayise
Bhekumusicayise - avatar
2 odpowiedzi
+ 8
They totally have 0 similarities (except that it can be used in a function). But anyway.... void can be said as a datatype that is empty. So its a datatype that literally stores... nothing. So now in functions you realise that you always have to output/return something. But what if its there just to do a "system.out.println"??? Then you have a problem yes? That is where void comes in, it basically allows you to return nothing. Try creating a void function, at the end just write "return;" and you will kinda get what I meant. Encapsulation is the act of hiding data from other code/classes/functions. It is quite important for good coding practice and when coding API/packages. (And hackers) Why is this important? Lets say that you created a list/array of alphabets for the user to access. Now you only want them to get, but not set/modify the array/list yes? That is where encapsulation comes into handy.
21st Aug 2017, 2:31 PM
Wen Qin
Wen Qin - avatar
+ 1
Those examples really do the trick! 😃 They're the main reason I understood what you just explained. 😂 Thanks Wen.
21st Aug 2017, 2:36 PM
Bhekumusicayise
Bhekumusicayise - avatar