Ask Question
23 February, 21:59

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

+4
Answers (1)
  1. 24 February, 00:44
    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?
Find an answer to your question ✅ “Explain why you would need both public and privatemembers in a class. ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers