Question

When designing a class, why is it generally a bad practice to make all fields public?

A It makes the class abstract.
B It violates the principle of encapsulation, leading to potential data corruption and reduced maintainability.
C It prevents the class from being inherited.
D It makes the class static.
E It causes compilation errors.
Practice Next

Hey! Ask a query