scala variance

It let’s Box[Cat] as subtype of Box[Animal] and is specified as below.

class Box[+T] (val content: T)

We can’t use var for access modifier.

Now

val animalBox: Box[Animal] = catBox 
 
// it works, no compilation error

Note: We can’t put something in covariant type. We can only get something out. For example, animalBox.content is possible but animalBox.content = dog is not possible.