Pretend we have 5 classes or interfaces: U, G, B, Z and X, each type has his variable:
U u;
G g;
B b;
Z z;
X x;
this will compile:
u = z;
x = b;
g = u;
x = u;
this wont compile:
u = b;
x = g;
b = u;
z = u;
g = x;
tree solution:
question: why is the G an interface and not abstract class?
also can G and X be both interfaces?
Why is the
Gan interface and notabstractclass?
Because U can extend exactly one class (abstract or not). Since X is a (abstract) class, then G must be an interface.
Can
GandXbe both interfaces?
Yes. Java allows classes (like U) to implement multiple interfaces.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With