Inheritance

·

1 min read

Today, I will talk about inheritance. It's very important in Object Oriented Programming. Here is an example:

image.png

The parent is animalFarm. The parent contains code that other classes will use. In this case, classes such as chicken will use the code that was written for animalFarm. This way, I don't have to keep typing "this.name,this.age", or this.farmName" over and over again. It saves me a lot of time. Lets say for example if you want to add more code. In that case, use the command super(name,age,farmName,taste). this.taste

Now you have all the code from animalFarm and new code from class chicken.