Visibility Modes in Inheritance
Visibility Modes in Inheritance
Modes in
Inheritance
Content
s
Which are What is
What is
different visibility of
protected
visibility class
mode?
modes? members?
What is effect
of visibility Assignment /
modes in Q&A
Exercise
Inheritance
with
Learn
Visibility
Modes
The private data members are The public data members The protected data
not accessible outside the are accessible outside the members are accessible by
class. They are accessible by class also. They are member functions within
member functions of its own accessible by member its class and within a class
class only. In this way data functions and objects of its which is immediately
hiding is implemented own class. derived from it.
Visibility
Modes
class A class can use all three visibility modes for
base declaring
{ its members
private: Members are visible to member functions within its class
………
………
protected: Members are visible to member functions of its own class
………. and of its derived class
……….
public: Members are visible to all functions & objects of class
………
………
};
Visibility
Modes
class B class D : public B
{ { ‘a’ is private
private: private: member of class
int a ; int total; ‘B’ , hence not
protected public: accessible in
: void put_total (void) class ‘D’
float b; {
public: total = a + b; // Not allowed
void getdata(int x, float y) ‘b’ is protected
total = b + 100 ;
{ member of class
cout << total ;
} a = x; b = y; ‘B’ , hence
}
}; accessible in its
};
derived class ‘D’
C++ program to implement Multilevel
Inheritance
c) The class members are accessible within the class and its immediate
derived class
3. Which mode supports the Data hiding property of OOP?
4. Which mode is useful to inherit the data members of base class into derived
class?
Assignment /
Exercise
Class: Student
Problem Definition: Data: Roll_no, Name
Write a C++ program to implement