Does Java natively support properties, like C#? Or when coding in Java, when trying to encapsulate variables, you are constrained to do it by getVariable()
and setVariable()
kinda methods?
Thanks
No
You don't have the concept of Properties in the Java language. You need to use getters and setters..
Java does not support C# like properties. You need getters and setters, but be careful that you don't accidentally give your user access to the encapsulated data by returning a reference to the object instead of a reference to a copy of it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With