Absolutely not, and your example demonstrates why. You've introduced a mutable variable value that may or may not be initialised - depending on the exact constructor used This is a potential source for a great many problems, and so Scala made the decision that all object creation should ultimately be directed via the primary constructor, this ensuring consistent initialisation If you want value to have a default value, then you can specify it as a default parameter (in 2.8+): abstract class Father(val value : Int = 0) or you can use the auxiluary constructor to achieve the same effect in Scala 2.7: abstract class Father(val value : Int) { def this() = this(0) } With Father defined in either of the above ways, the following definitions of child are both valid: class Child(v:Int) extends Father(v) class Child extends Father() You can also make value a var if you absolutely have to, but I strongly advise against it If the semantics of value mean that it's valid to not be initialised, then the correct Scala idiom is to declare it as OptionInt : abstract class Father(val value : OptionInt = Some(0)).
Absolutely not, and your example demonstrates why. You've introduced a mutable variable value that may or may not be initialised - depending on the exact constructor used. This is a potential source for a great many problems, and so Scala made the decision that all object creation should ultimately be directed via the primary constructor, this ensuring consistent initialisation.
If you want value to have a default value, then you can specify it as a default parameter (in 2.8+): abstract class Father(val value : Int = 0) or you can use the auxiluary constructor to achieve the same effect in Scala 2.7: abstract class Father(val value : Int) { def this() = this(0) } With Father defined in either of the above ways, the following definitions of child are both valid: class Child(v:Int) extends Father(v) class Child extends Father() You can also make value a var if you absolutely have to, but I strongly advise against it. If the semantics of value mean that it's valid to not be initialised, then the correct Scala idiom is to declare it as OptionInt: abstract class Father(val value : OptionInt = Some(0)).
Your Child constructor have no parameter and you are trying to instanciate it with one! You have to declare a parameter in your Child constructor and then pass it to the Father class, for example: class Child(v:Int) extends Father(v) { } val a = new Child(42).
You should provide a link to somewhere that says why this is so. My lack of knowledge of Scala – and so inability to select a good link – was why I didn't turn my (slightly facetious) comment into an answer… – Donal Fellows Sep 25 '10 at 12:39.
A quite simple exercise from Cay Horstmann's book « Scala for the impatient » keeps puzzling me. Rewrite it to use explicit fields and a default primary constructor. I'm not sure about I am supposed to do.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.