public class Cls1{
public foo(){
doX();
}
}
public class Cls2{
public foo(){
doY();
}
}
Cls2 cls = new Cls2();
cls.foo();
Is there a way to do inheritance in java that java runs both doX and doY when the user calls the function with foo?
Yes, but you have to do it explicitly:
Note: I assume you meant for Cls2 to extend Cls1, otherwise your question makes no sense at all.