class A
{
public void Foo() {}
}
class B extends A
{
}
class C extends B
{
public void Foo(开发者_如何学编程) {}
}
Does C's Foo() override A's even though B did not override it? Or do I have to add a stub in B that calls the super's method for each one I want to override in C?
Even though B did not mention it, Foo
should still be available to it due to inheritance. By extension, then, Foo
is also available to subclass C and should be able to be overridden thanks to polymorphism.
Instances of C, therefore, will use c.foo()
(however it is defined), where as instances of A and B will make use of a.foo()
because they have not yet been overridden.
Yes C overrides Foo() of A.
This is due to inheritance, though B doesn't override Foo() , Foo() is inherited from A by B.
And as C extends B, Foo() is inherited by C and overriding happens as C defines Foo().
精彩评论