Scala abstract class

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

abstract class are pretty similar to trait we saw before. But there are some slight differences.

You recognize the same keywords we learned about when we learned about trait. You can see extends, protected and override.

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

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

To practice the concepts of Object Oriented Programming, Try to access the fields of Shape in the child classes. You notice that only lengthOfSides is protected and not the other ones. Remember class ? By default fields are private in a class. Try to add methods, maybe the area ?

Reveal more information and clues
Load Exercise