Sponsor Area

NCERT Solutions for Class 12 Help.html Computer Science With C++ Chapter 2 Object Oriented Programming

Object Oriented Programming Here is the CBSE Help.html Chapter 2 for Class 12 students. Summary and detailed explanation of the lesson, including the definitions of difficult words. All of the exercises and questions and answers from the lesson's back end have been completed. NCERT Solutions for Class 12 Help.html Object Oriented Programming Chapter 2 NCERT Solutions for Class 12 Help.html Object Oriented Programming Chapter 2 The following is a summary in Hindi and English for the academic year 2025-26. You can save these solutions to your computer or use the Class 12 Help.html.

Question 1
CBSEENCO12011519

Differentiate between private and public members of a class in the context of Object Oriented Programming. Also, give a suitable example illustrating accessibility/non-accessibility of each using a class and an object in C++.

Solution

A class can have multiple public, protected, or private access modifier.

A public class of member or function is accessible from anywhere outside the class but within the program. You can set and get the value of public variables without any member function as shown in the given example.
A private member variable or function cannot be accessed, or even viewed from outside the class. Only the class and friend functions can access private members.By default, all the members of a class would be private, for example.

classMyClass
{
    public:int a;
    private:int b;
};
    int main()
{
   MyClass obj;
   obj.a =10;//Allowed
   obj.b=30;//Not Allowed, gives compiler error}

Sponsor Area