If I have a class constellation in Scala like this:
class A {
def foo() = "bar"
}
class B extends A {
override def foo() = "BAR"
}
class C extends B {
}
is it possible in class C to explicitly call the method foo that was defined in A?
If I have a class constellation in Scala like this:
class A {
def foo() = "bar"
}
class B extends A {
override def foo() = "BAR"
}
class C extends B {
}
is it possible in class C to explicitly call the method foo that was defined in A?
No, but you can do something similar with multiple trait inheritance:
trait A { def foo = "from A" }
class B extends A { override def foo = "from B" }
class C extends B with A {
val b = foo // "from B"
val a = super[A].foo // "from A"
}
No, you can't, because it violates encapsulation. You are bypassing your parents behaviour, so C is supposed to extend B, but you are bypassing this.
Please see Jon Skeets excellent answer to the same question Why is super.super.method(); not allowed in Java?.
Please note that you can access the field by reflection, but you don't want to do that.
No. And I would leave it at that, but apparently SO wants me to go on for 30 characters.