Reputation: 421290
I noticed that I can extend a class and at the same time pass parameters to the extended class:
scala> class SomeClass(val str: String)
defined class SomeClass
scala> class SubclassOne extends SomeClass("one")
defined class SubclassOne
scala> class SubclassTwo extends SomeClass("two")
defined class SubclassTwo
scala> val obj : SomeClass = new SubclassOne
obj: SomeClass = SubclassOne@2dca4eb4
scala> obj.str
res0: String = one
I'm working a lot with case classes, where ClassName(args)
actually creates an object, so to me it looks like I'm extending an object, but I'm not sure here.
Does it perhaps mean that I'm extending the class, and automatically pass an argument to the super constructor?
Upvotes: 3
Views: 3151
Reputation: 370435
Does it perhaps mean that I'm extending the class, and automatically pass an argument to the super constructor?
Yes, that is exactly what it means.
Upvotes: 10