extendskeyword being used to specify that an object inherits from another object. This is called implementation inheritance since an object takes all of the behaviors from its parent and can use them like its own.
extendsis used, these are the things that are inherited:
extendsanother object, its constructor will automatically call the parent's constructor. However, this does have some limitations:
superkeyword comes in! When
superis called, Java will know to not call the default constructor anymore. Here's an example:
@Overridetag is technically optional, but it's highly suggested because it makes sure that you are indeed overriding something and not just making a new method! (Remember, it has to have the same name and parameters as a method in one of its parents.)
getCount(Fruit fruit)that counts how many fruits of that type we have? We might also want to allow users to pass in the name of the fruit to do the same thing-
getCount(String fruit). Java will allow us to make both of these methods in the same class!
@Overridetag, you can relate it back to this concept!
abstract void doSomething()) behave just like methods in interfaces.