I have this Java code:
class Super {
public static void foo() { bar(); }
public static void bar() { out.println("BAR");}
public static void main(String[] args) {
foo();
}
}
class Sub extends Super {
public static void bar() { out.println("bar"); }
}
And I would like to see what he does in Scala, but cannot find how to write an equivalent. This is what I have:
object Super {
def foo() { bar() }
def bar() { println("BAR")}
def main( args : Array[String]) {
foo()
}
}
object Sub extends Super {
override def bar() { println("bar")}
}
But it does not compile. Is it because an object cannot inherit?
source
share