Skip to content

Commit

Permalink
add ScalaBasic/TraitDemo14.scala
Browse files Browse the repository at this point in the history
  • Loading branch information
yennan.liu committed Oct 4, 2021
1 parent 1ba5185 commit 575a99b
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/main/scala/ScalaBasic/TraitDemo14.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package ScalaBasic

trait A_TraitDemo4 {
def init(a: Int): Unit = {
print("A")
}
}

trait B_TraitDemo4 {
def init(a: Int): Unit = {
print("B")
}
}

class C_TraitDemo4 extends A_TraitDemo4 {
def init(): Unit = {
print("C\n")
}
}

class D_TraitDemo4 {
val name:String = "123"

def this(name:String){
this()
println(name)
}

def apply():Unit = {
println("D apply")
}
}

object TraitDemo14 extends App {
println ("123")
val d = new D_TraitDemo4("DDD")
d()
d.apply()
println ("456")
}

0 comments on commit 575a99b

Please sign in to comment.