0

PLEASE EXPLAIN THE OUTPUT OF THIS CODE??

I don't understand this code. It outputs 11 and I don't know why. I understand that it defines Class A, with a function called foo() inside Class A. I understand that it defines Class B. I don't understand what it means when it has the "class B:public A" in there and I don't really understand anything else in the code, except I do understand that in the end, after it goes into main(), it initiates func(a) and func(b), meaning that it initiates the function called func() but I DO NOT understand why that comes out with an 11. Please help! And please be thorough and specific! I prefer to have TOO MUCH explained rather than too little!

4th May 2018, 11:20 AM
Jackson Meddows
Jackson Meddows - avatar
1 Resposta
+ 1
class B inherits from class A (that's what class B:public A) means. when you call func on a, it executes the foo() method of A and outputs one. then you execute foo() on b, but because the parent class of the B class has the method foo(), the A class foo method is executed and outputs 1 again. thus you get 11
4th May 2018, 11:37 AM
hinanawi
hinanawi - avatar