line 4 is a bad habit.
just say
A(int a2b) {a = a2b;} //thisis clutter/bloat just give the input parameter another name so it isnt needed.
you can inherit the classes so that B can access the methods of A, such that
B y;
y.A(42); //the B class object Y calls the A method because you inherited it, which then sets B's a variable, because it inherited that too.
I am a little rusty on doing this -- it seems extra weird because A() sets a, so I don't really know off the top of my head what is needed to do that. If A() just did a print to the screen, though, borrowing it would be straightforward -- maybe try that as a starting point. There are any number of OOP features I do not use a lot; about all I do with friend is apply an overload so cout will work on an object, which is boilerplate code that you can get anywhere without having to dig into it /blush
Our instructer didn't allow us to use friend keyword in the project. I researched on the Internet and I found a getInstance() function which is used in Singleton Design Pattern. Hence, I will do some more research and try it in my code.
Thank you for your contributions. After my research, I will write here.