标签:
object triatScala { def main(args: Array[String]): Unit = { val t1 = new PianoTeacher t1.playPiano t1.teach } } //公共父类 class Human{ println("Human") } //继承父类的接口 trait TTeacher extends Human { println("TTeacher") def teach } //继承父类的接口,并且拥有自己的方法 trait PianoPlayer extends Human { println("PianoPlayer") def playPiano = {println("I’m playing piano. ")} } //继承父类的类并且混入两个接口实现接口中的方法 实现顺序是按照从左到右 class PianoTeacher extends Human with TTeacher with PianoPlayer { override def teach = {println("I’m training students. ")} }
//AOP 面向切面编程 trait Action { def doAction } trait TBeforeAfter extends Action { //使用抽象方法覆盖父类的接口实现中需要制定父类的方法,这个方法在具体的类中实现 abstract override def doAction { println("Initialization") super.doAction println("Destroyed") } } class Work extends Action{ //具体实现父类方法 override def doAction = println("Working...") } object triatScala { def main(args: Array[String]): Unit = { val work = new Work with TBeforeAfter work.doAction } }
package com.scala.spark package object people { val defaultName = "Scala" } package people { class people { var name = defaultName } } import java.awt.{Color,Font} import java.util.{HashMap=>JavaHashMap} import scala.{StringBuilder => _}
package spark{ package navigation{ //private[spark]表示该类在spark包下有访问权限 private[spark] class Navigator{ //protected[navigation]表示该方法在navigation包下有访问权限 protected[navigation] def useStarChart() {} class LegOfJourney { //private[Navigator]表示该常量在navigation包下有访问权限 private[Navigator] val distance =100 } //private[this]表示该常量在navigation包下有访问权限 private[this] var speed = 200 } } package launch{ import navigation._ object Vehicle { //private[launch]表示该常量在launch该同级的包可以实例化 private[launch] val guide = new Navigator } } }
今天就学到这儿.....
百度视频地址:http://pan.baidu.com/s/1ntzOmDz
标签:
原文地址:http://www.cnblogs.com/524646016-zhang/p/zhangsh_dt_scala_05.html