Implements vs extends
extends
means:
The new class is a child. It gets benefits coming with inheritance. It has all properties, methods as its parent. It can override some of these and implement new, but the parent stuff is already included.
implements
means:
The new class can be treated as the same "shape", while it is not a child. It could be passed to any method where the Person
is required, regardless of having different parent than Person
When a subclass extends a class, it allows the subclass to inherit (reuse) and override code defined in the supertype.
When a class implements an interface, it allows an object created from the class to be used in any context that expects a value of the interface.
Last updated