blob: d408ed550e6493d7daba7b0f40d883d7885d2054 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
class Foo {
class Bar {
def foo = 1
}
}
class SubFoo extends Foo {
class SubBar {
def foo = 42
}
}
object Test {
def main(args: Array[String]): Unit = {
// Let's create some instances:
val foo = new Foo
val fooBar = new foo.Bar
assert(fooBar.foo == 1) //> res0: Int = 1
// ok
val subFoo = new SubFoo
val subFooBar = new subFoo.SubBar
assert(subFooBar.foo == 42) //> res1: Int = 42
// ok
val superFoo: Foo = subFoo
val superFooBar = new superFoo.Bar
assert(superFooBar.foo == 1) //> res2: Int = 1
// NOT OK!
}
}
|