answersLogoWhite

0


Best Answer

this is the reason for security purpose

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the reason for making Data as Private Member of a Class?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Can you access in drive class from base class private data?

Base class should no knowledge about derived classes. The "private" modifier on a data member means private to the class which defined it. Base class cannot directly reference/access the private data member of the derived class, and the derived classes cannot access the private data member defined in the base class. Either way the accessing the private data member should be done via properties or getters


Is the default access specifier same as protected?

A private member of a class can only be accessed by methods of that class. A protected member of a class can only be accessed by methods of that class and by methods of a derived class of that class.


Difference between public member and private member of a class in Java?

public members can be accessed from outside the class they were declared in, private members can only be accessed from within the class they were declared in. Private members are commonly manipulated through get/set methods, which allows for greater encapsulation and hides the implementation from the calling function. Example: class sampleClass{ private: int private_member; public: int public_member; public: void setPrivateMember(int x){private_member = x;}; // private members can be accessed from within the class that they are declared in public: int getPrivateMember(){return private_member;}; }; int main() { sampleClass A; A.public_member = 5; // Perfectly legal A.private_member = 7; // Syntax error, this will not compile A.setPrivateMember(7); // Legal cout << A.getPrivateMember(); // Legal return 0; }


Which base class member functions are not inherited by a derived class?

Derived classes only inherit the protected and public members of their base classes. Private member functions cannot be inherited by a derived class.


What is the purpose of the keyword private?

The private keyword is used to ensure that no other classes will be able to access (view or modify) that class member.

Related questions

Can you access in drive class from base class private data?

Base class should no knowledge about derived classes. The "private" modifier on a data member means private to the class which defined it. Base class cannot directly reference/access the private data member of the derived class, and the derived classes cannot access the private data member defined in the base class. Either way the accessing the private data member should be done via properties or getters


What is the difference between public and private in c plus plus?

A private member can only be accessed by other methods of the same class, while a public member can be accessed by methods of any class or by non class code.


What is the meaning private member of a class?

It means the member is only accessible to the class itself, and to friends of the class. Protected members are the same as private members but are also accessible to derived classes. Public members are fully accessible.


Is the default access specifier same as protected?

A private member of a class can only be accessed by methods of that class. A protected member of a class can only be accessed by methods of that class and by methods of a derived class of that class.


What are Public and Private inheritance in c plus plus?

Public, protected and private inheritance determine how the public and protected base class members are inherited by the derived class. Private members are never inherited and are therefore unaffected by the type of inheritance (they remain private to the base class). The following table summarises how inheritance affects accessibility of base class members with respect to the derived class: public inheritanceprotected inheritanceprivate inheritancepublic member of base classpublic member of derived classprotected member of derived classprivate member of derived classprotected member of base classprotected member of derived classprotected member of derived classprivate member of derived classprivate member of base classprivate member of base classprivate member of base classprivate member of base class Note that accessibility to individual public and protected base class members can be overridden within the derived class, regardless of the type of inheritance specified.


Difference between public member and private member of a class in Java?

public members can be accessed from outside the class they were declared in, private members can only be accessed from within the class they were declared in. Private members are commonly manipulated through get/set methods, which allows for greater encapsulation and hides the implementation from the calling function. Example: class sampleClass{ private: int private_member; public: int public_member; public: void setPrivateMember(int x){private_member = x;}; // private members can be accessed from within the class that they are declared in public: int getPrivateMember(){return private_member;}; }; int main() { sampleClass A; A.public_member = 5; // Perfectly legal A.private_member = 7; // Syntax error, this will not compile A.setPrivateMember(7); // Legal cout << A.getPrivateMember(); // Legal return 0; }


Can you return a reference to public data member?

Yes, but since it is public there is no need to; any code outwith the class can access a public data member directly. If it were a private data member, then returning by reference would defeat the point of making it a private data member in the first place; you might as well make it public. Private data members should always be returned by value, never by reference and never by pointer, and data members should only be declared public if they are not critical to the internal operation of the class.


What is private specifier in c plus plus?

The private specifier states that the member can only be accessed by the containing class, and not by any derived class, nor by any other code outside of a class.


Can you define the constructor as private?

Yes, you can. Making a constructor private ensures that no other class can instantiate that class you just created with a private constructor. It is usually used in Singleton Patterns.


Which base class member functions are not inherited by a derived class?

Derived classes only inherit the protected and public members of their base classes. Private member functions cannot be inherited by a derived class.


What is the purpose of the keyword private?

The private keyword is used to ensure that no other classes will be able to access (view or modify) that class member.


What is the use of private constructor in c plus plus?

Private construction prevents objects from the class from being instantiated other than via a static member function of the class, a friend function or a friend class.