Is there any way to make instance variables \"private\"(C++ or Java definition) in ruby? In other words I want following code to result in an error.
class B
It isn't possible to do what you want, because instance variables aren't defined by the class, but by the object.
If you use composition rather than inheritance, then you won't have to worry about overwriting instance variables.