On 26.06.20 16:34, Milles, Eric (TR Tech, Content & Ops) wrote:
Sorry for replying to my own...

class A {
   def x = 1
   def getX() { 2 }
   def m() { return x }
}

print new A().m() // output 1 or 2?

If we go by the principle of "when in doubt, do it like Java", the
answer is quite clear: 1. Of course nothing is clear ;) You can actually
expand the question to: Is there a difference between "return x" and
"return this.x" in m()?

class B extends A {
   def x = 3
   def getX() { 4 }
   def m2() { return x }
   def m3() { return super.x }
}

print new B().m3() // output 1 or 2?
print new B().m2() // output 3 or 4?
print new B().m() // output 1 or 2 or 3 or 4?

For me the result should be (old):
1
3
1

and with the changes to super (new):
2
3
1

if I understood OC right we would get:
2
4
4



bye Jochen


Reply via email to