الشرح التفصيلي لجميع شرائح المحاضرة (Slide-by-Slide) مدعوم بشرح الأكواد سطراً بسطر (Line-by-Line Code Explanation)
1. If a base class pointer points to a derived class object, and calls a NON-virtual overridden function, whose function is actually executed?
2. What is another term for Run-time Polymorphism achieved through virtual functions?
1. Which of the following defines an Abstract Class in C++?
2. What happens if a Derived class inherits from an Abstract Base class but fails to implement (override) one of the pure virtual functions?
virtual: بنحطها في الأب قبل الدالة. بتخلي الكومبايلر يبص على الكائن الحقيقي مش نوع البوينتر ← Late Binding = True Polymorphism!virtual void func() = 0; ← دالة فاضية الأب مبيكتبلهاش كود، وبيسيب الأبناء يكتبوها.Question: Differentiate between Early Binding and Late Binding in C++. Explain the role of the `virtual` keyword, Pure Virtual Functions, and Abstract Classes. Provide a code example showing polymorphic behavior.
Q1:
Q2:
Q1: Declare a Pure Virtual Function called calculateArea that returns a float in a class Shape.
Q2: Create an array of 3 pointers to the base class Shape.
Q3: Given Shape *arr[3] and derived classes Circle and Square, assign a new Circle object to the first element and a Square object to the second element.
a) What is the error in this code?
b) If we remove the error line, what is the output?
c) What is the benefit of having Vehicle *ptr point to new Car()?