Created
September 2, 2015 20:10
-
-
Save invkrh/0654f97b8ee6e333ef8b to your computer and use it in GitHub Desktop.
Show that recursive call need to be final or private (avoid overriding)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class C { | |
def fact(n: Int, result: Int): Int ={ | |
println("super") | |
if(n == 0) result else fact(n - 1, n * result) | |
} | |
} | |
class C2 extends C { | |
override def fact(n: Int, result: Int): Int = { | |
println("sub") | |
2 * super.fact(n, result) | |
} | |
} | |
println((new C).fact(5, 1)) | |
println((new C2).fact(3, 1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment