Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is "length" attribute public in String class?

In Java, I'm wondering why the "length" attribute of the String class isn't private? Isn't it a bad practice according to encapsulation principle? Why is there no method like "getLength()" for instance?

PS: Sorry for my English, I'm still improving it.

like image 609
lost3den Avatar asked Dec 02 '25 10:12

lost3den


1 Answers

In fact, it really is private. Maybe your confusing with the length() method?

like image 172
bruno conde Avatar answered Dec 05 '25 00:12

bruno conde



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!