class B {
int m() {
return new A().m();
}
}
or
class B {
private A a = new A();
int m() {
return a.m();
}
}
or
class B {
private A a;
public B(A a) {
this.a = a;
}
int m() {
return a.m();
}
}
solved Inheritance vs. Delegation [duplicate]