0
List the drawbacks of classes with all public data members.
C++ question
2 odpowiedzi
0
Well if something is public, chances are it is already being depended upon in another class. It may be therefore costly to change its implementation.
But if it is private, you can change its implementation in a whim, has long has the public API still works correctly.
This is called data hiding and is a important part of encapsulation, one of the major pillars of OOP.
+ 5
you cannot say drawback . If you will read definition of public members u will understood the drawbacks and advantage both .
everyone want to access data so public is better ...... 😆😆😂
public member is accessible from anywhere outside the class but within a program. You can set and get the value of public variables without any member function
Access modifier provides you the authority to control your data depending upon the scenarios. If you are working in a bank domain then you have to use private data members to keep your data hidden from other users, authority is in your hand. You can make them public if you want to but it won’t be a great approach because in that case, anyone can change your data at any time