Member variable to be only inherited by immediate child

In reply to bhupeshpaliwal:
It’s not possible. By default all the variables are public until they are encapsulated using identifiers like “local” or “protected”. If declared string s as protected then all the subclasses will be able to access it.

Can you please brief your purpose here.