1

From the link http://www.scala-lang.org/old/node/117

It gives an example that a trait extends an abstract class. Since abstract class has constructor, how could it happen? Does it mean abstract class and trait have the same position?

worldterminator
  • 2,968
  • 6
  • 33
  • 52
  • https://stackoverflow.com/questions/12854941/why-can-a-scala-trait-extend-a-class This relates to an abstract class as well. – Dmytro Mitin Oct 04 '17 at 13:37

1 Answers1

1

They are for sharing interfaces, fields and type between classes and both of them are not instantiatable. And a abstract class extends a trait and vice versa. But since A class in scala can extend only one superclass,

abstract class A
abstract class B
trait AA extends A
class C extends AA // ok  class C's super class is A
class C extends B with AA // NG trying to have 2 super class

like I mentioned at the beginning, they are non-instantiatable. So You do not need to care the abstract class's constructor. It will be called when a class which extends it is created and instantiated.

suish
  • 3,253
  • 1
  • 15
  • 34