الشرح التفصيلي لجميع شرائح المحاضرة (Slide-by-Slide) مدعوم بشرح الأكواد سطراً بسطر (Line-by-Line Code Explanation)
1. What is the primary advantage of using Inheritance in OOP?
2. Which access specifier should be used in a Base class if you want the data to be hidden from the `main()` function, but fully accessible to its Derived (child) classes?
1. When creating an object of a Derived class, what is the exact order of execution for Constructors and Destructors?
2. In Multiple Inheritance, if two base classes have a function with the exact same name, and the derived class calls it, an 'Ambiguity Error' occurs. How do you resolve this in C++?
class Child : public Parent { }; ← النقطتين (:) هي اللي بتعمل الوراثة.Child(int p, int c) : Parent(p) { }.class C : public A, public B { };. لو في دالة بنفس الاسم في الأبهات بيحصل Ambiguity والحل بالـ Scope Resolution obj.A::func();.Question: Explain the concept of Inheritance in C++. Discuss the `protected` access modifier, the order of Constructor/Destructor calls, how to pass arguments to a Base class constructor, and the Ambiguity problem in Multiple Inheritance with its solution.
Q1:
Q2:
Q1: Declare a class Dog that inherits publicly from a class Animal.
Q2: Write a Derived constructor that passes value x to the Base constructor using an initialization list.
Q3: Declare a class C that inherits from both A and B (Multiple Inheritance).
a) What is the output?
b) Why is width declared as protected instead of private?
c) Can we write cout << s.width; in main()?