+ 1
Explanation of this code?
Java Inherintance https://code.sololearn.com/cSKi0U5dFfdf/?ref=app
6 Respostas
+ 2
yes if you want to call the parent class's f method, you can use the super keyword:
public void f(){
super.f();
System.out.println("b");
}
+ 2
Thanks. You were kind.
+ 1
This is an inheritance situation
B extends from A therefor B can be handled as A
the g method takes an A so B is valid because it extends from A.
the output will be 'b' because the class B overrides the definition of the f method.
It does becomes a little complex to understand with letters for class and method names so I hope I manage to clarify it a bit.
+ 1
the method is being overridden so it won't call both the A.f and B.f, only B.f
+ 1
It's overriden because this methods are not constructors?
0
So its used a method with an A obj as argument and its called the function. However instead of giving "ab" gives b!