Ask Question
6 August, 21:20

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

+1
Answers (1)
  1. 6 August, 21:21
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers