Exercise 2: Consider the following C++ program declaration (This is not full pro
ID: 3701465 • Letter: E
Question
Exercise 2: Consider the following C++ program declaration (This is not full program it is only like a pseudocode). 2 class vehicle 1 protected: int x; public: void f()1...J; 4 5 6 7-class car: public vehicle 8 protected: int x1; 9 10>; 12- class small_car: public car 13 14 J; 15 public: int x2; 16- class truck: public vehicle ( 17 18 19 20 21 22 car obj1; 23 24 25 26 27 public: fOt...); int main() return e; 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) obj1.x obj1.f objl.xl, obj1.x2Explanation / Answer
obj1.x: not allowed, x is protected member, it can not be accessed outside the class
obj1.f() : allowed, as f is public member
obj1.x1 : not allowed, as it is a protected member
obj1.x2 : not allowed, as x2 is not a member of class car
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.