Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Exercise 2: Consider the following C++ program declaration This is not full prog

ID: 3701293 • Letter: E

Question

Exercise 2: Consider the following C++ program declaration This is not full program it is only like a pseudocode) class vehicle 2- 3 4 5 6 protected: int x; public: void f()1...J; d; class car: public vehicle protected: int x1; 8 9 b; class small_car: public car d; class truck: public vehicle f 10 12 13 14 15 16 17 18 19 20 21 public: int x2; public: f)f.. .^; int main () car obj1; 23 24 25 26 27 return For each of the following expressions, say whether it is allowed in the code of main or not; justify your answer. (you can edit and complete the code as you want to check your answers) objl.x, obj1.f) , objl.xl, objl.x2

Explanation / Answer

obj1.x --> It is a valid expression as car class extends vehicle class with public access modifier. So it has access to all public and protected field of vehicle class

obj1.f --> It is a valid expression as car class extends vehicle class with public access modifier. So it has access to all public and protected field of vehicle class
obj1.x1 --> It is a valid expression as x1 is a instance field in car class

obj1.x2 --> It is not a valid expression as x2 is in child class of car which is not accessible