Ask Question
17 February, 18:12

Explain why you would need both public and privatemembers in a class.

+3
Answers (1)
  1. 17 February, 19:17
    0
    In a class, a public data member are those member which can be accessible to all other classes in the computer program. By using public data member a class can modify its data member and its member function. Hence, the key member in class are not be declared as public.

    It is declared as:

    class public

    {

    public; / / public access specifier

    int a, b; / / Data Member

    }

    In a class, a private data member are only access by member function inside the class as, it is completely invisible from the outside world. In this, member function and class variable are private by default.

    class private

    {

    private; / / private access specifier

    int a, b; / / Data Member

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Explain why you would need both public and privatemembers in a class. ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers