In computer science , inheritance is most important to cbse board of class 12 ?
Answers
Yes it is most important.
Important Questions for Class 12 Computer Science (C++) – Inheritance (Extending Classes)
Previous Years Examination & Important Questions
2 Marks Questions
Question 1:
Differentiate between protected and private members of a class in context of Object Oriented Programming. Also give a suitable example illustrating accessibility/non-accessibility of each using a class and an object in C++. All India 2017
or
What is the difference between protected and private members of a class? Give a suitable example in C++ to illustrate with its definition within a class. All India 2015C
Answer:
Private visibility A member declared as private can be accessed only in class. It means that it cannot be accessed outside the class.
Protected visibility A member declared as protected can be accessed inside the class as well as inside its sub class only.
e.g.
class Super
{
private:
int x;
protected:
int y;
};
class Sub : protected Super
{
private:
int z;
public:
void disp()
{
cout<<x<<y<<z;
/*Here y and z can be accessed but x cannot be accessed because it is a private member of Super class*/
}
}:
Question 2:
Differentiate between members, which are present within the private visibility mode with those which are present within the public visibility modes. Delhi 2011
Answer:
Private visibility A member declared as private can be accessed only in class. It means that it cannot be accessed outside class.
Public visibility A member declared as public can be access inside the class as well as outside the class with object of that class.
e.g. class Super
{
private
int x;
public:
int y;
}:
class sub : private super
{
private:
int z;
public:
void show()
{cout<<x<<y<<z;
/*Here y and z can be accessed because it a private member of super class*/
}
};