Junior — Middle
Can it be considered that the Init method in the derived class inherits or overrides the implementation from the base class?
sobes.tech AI
Answer from AI
The Init method in a derived class does not inherit the implementation from the base class if it is redefined (that is, with the same name but its own implementation). In this case, it is said that the method is overridden. Overriding means that when the method is called on an object of the derived class, its version of the method will be used, not the base class's.
If the Init method in the derived class is not declared, it is inherited from the base class and used without changes.
Example in C#:
class BaseClass {
public virtual void Init() {
Console.WriteLine("Base class Init");
}
}
class DerivedClass : BaseClass {
public override void Init() {
Console.WriteLine("Derived class Init");
}
}
Here, Init in DerivedClass overrides the method from BaseClass. If Init is not declared in DerivedClass, the base implementation is used.