package com.scala.idle
object TraitOrAbstractClass {
def main(args: Array[String]): Unit = {
}
}
/**
* 继承两个trait,N多方便啊!
*/
class TestClass000 extends Trait000 with Trait001{
}
/**
* 继承两个abstract class,Error了。Error信息如下:
* Multiple markers at this line
- class AbstractClass001 needs to be a trait to be
mixed in
- class AbstractClass001 needs to be a trait to be
mixed in
*/
class TestClass001 extends AbstractClass000 with AbstractClass001{
}
/**
* 构造带参数的构造函数,trait,你可以吗?报错信息如下:
* traits or objects may not have parameters
* 但是abstract class是Ok的
*/
trait Trait003(i : Int){
}
/**
* 构造带参数的构造函数,abstract class 是Ok的
*/
abstract class AbstractClass003(i : Int){
}
trait Trait000{
def showTrait000 = {
println("showTrait000 ...")
}
}
trait Trait001{
def showTrait001 = {
println("showTrait001 ...")
}
}
abstract class AbstractClass000{
def showAbstractClass000 = {
println("showAbstractClass000 ...")
}
}
abstract class AbstractClass001{
def showAbstractClass001 = {
println("showAbstractClass001 ...")
}
}