The example uses a and b in the superclass, and then x and y in the subclasses with implicit constructor:
// With class parameters:
// implicit field declarations and constructor
class IntPair(a: int, b: int) {
def sum() -> int {
return a + b;
}
}
...
// Alternative C:
// class parameters, implicit constructor and call to super
class IntTripleC(x: int, y: int, c: int) extends IntPair(x, y) {
def sum() -> int {
return a + b + c;
}
}
I expect this to work fine when I reuse the field names, but it errors:
// With class parameters:
// implicit field declarations and constructor
class IntPair(a: int, b: int) {
def sum() -> int {
return a + b;
}
}
...
// Alternative C:
// class parameters, implicit constructor and call to super
class IntTripleC(a: int, b: int, c: int) extends IntPair(a, b) {
def sum() -> int {
return a + b + c;
}
}
> v3c test.v3
[test.v3 @ 27:18] MemberRedefined: member "a" redefined
class IntTripleC(a: int, b: int, c: int) extends IntPair(a, b) {
^
[test.v3 @ 27:26] MemberRedefined: member "b" redefined
class IntTripleC(a: int, b: int, c: int) extends IntPair(a, b) {
The example uses
aandbin the superclass, and thenxandyin the subclasses with implicit constructor:I expect this to work fine when I reuse the field names, but it errors: