Skip to content

Commit c21dc2e

Browse files
fix: needs var for Dog extends abstract class
In the _Dog extends abstract class_ (aka Scala 2 way) `var` keyword is missing in the class defition ``` class Dog(name: String, age: Int) extends Pet(name): ... ``` As a result the `Dog` class fails to compile with the following error `class Dog needs to be abstract, since def age: Int in class Pet is not defined` adding `var` to the definition solves to problem ``` class Dog(name: String, var age: Int) extends Pet(name): ... ```
1 parent a5b859a commit c21dc2e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

_overviews/scala3-book/domain-modeling-tools.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ abstract class Pet(name: String):
415415
def age: Int
416416
override def toString = s"My name is $name, I say $greeting, and I’m $age"
417417

418-
class Dog(name: String, age: Int) extends Pet(name):
418+
class Dog(name: String, var age: Int) extends Pet(name):
419419
val greeting = "Woof"
420420

421421
val d = Dog("Fido", 1)

0 commit comments

Comments
 (0)