How is memory allocated for each instance of a class?
For each instance of the class, memory is allocated to only its member variables i.e. each instance of the class doesn't get it's own copy of the member function. All instances share the same member function code. You can imagine it as compiler passing a hidden this pointer for each member function so that it operates on the correct object.
Why do all instances share the same member function code?
All instances share the same member function code. You can imagine it as compiler passing a hidden this pointer for each member function so that it operates on the correct object. In your case, since C++ standard explictly prohibits 0 sized objects, class A and class B have the minimum possible size of 1.
Does class Y have access to Class X's Private Members?
No, but it has access to class X's private members, just as if it were a member. Class Y is a friend of class X, which means the member functions of class Y have access to the private members of class X. Does the friend key word appear in class Y's declaration or in class X's declaration?