OOP is great when you write APIs/libraries (your examples),
but is useless or even counter productive when writing applications, where encapsulation or inheritance just obfuscate everything.
My main grip with Java is that everything is by default a library.
But there is hope, recent changes in Java, records and pattern matching move away from that idea.