Explain virtual base class? What is the difference between private and protected visibility modifier?
|Subject||Object Oriented Programming|
|NU Year||Set: 5.(c) Marks: 5+1=6 Year: 2011|
Ambiguity can arise when several paths exist to a class from the same base class. This means that a child class could have duplicate sets of members inherited from a single base class.
- C++ solves this issue by introducing a virtual base class. When a class is made virtual, necessary care is taken so that the duplication is avoided regardless of the number of paths that exist to the child class.
Java has four access modifier namely private, protected and the public. package level access is default access level provided by Java if no access modifier is specified. These access modifiers are used to restrict accessibility of a class, method or variable on which it applies. We will start from private access modifier which is most restrictive access modifier and then go towards public which is least restrictive access modifier, along the way we will see some best practices while using access modifier in Java and some examples of using private and protected keywords