Scala abstract class

This SKB is going to continue our progress in the Object Oriented Programming aspect of Scala.

abstract classare pretty similar totraitwe saw before. But there are some slight differences.

You recognize the same keywords we learned about when we learned abouttrait. You can seeextends,protectedandoverride.

There are more differences but for the moment let's go one step at a time.

The main difference you can notice compare totraitis that you are able to have a constructor directly when youextendstheabstract class. This is pretty convenient to build simple pattern. We are going to see more about this in the context ofenumeration.

To practice the concepts of Object Oriented Programming, Try to access the fields ofShapein the child classes. You notice that onlylengthOfSidesisprotectedand not the other ones. Rememberclass? By default fields areprivatein aclass. Try to add methods, maybe the area ?

Reveal more information and clues
Load Exercise