首页 > 其他 > 详细

第8讲 构造器

时间:2015-08-17 00:49:09      阅读:214      评论:0      收藏:0      [点我收藏+]

温故而知新 DT大数据梦工厂第8讲 构造器
百度云盘连接http://yun.baidu.com/share/home?uk=4013289088#category/type=0
//class Teacher {
// var name : String = _
// private var age = 27
// private[this] val gender = "male"
//
// def this(name:String){
// this
// this.name = name
// }
//
// def sayHello(){
// println(this.name + ":" + this.age + " : " + this.gender)
// }
//}

class Teacher private (val name : String, val age : Int){
println("This is the primary constructor!!!")
var gender : String = _
println(gender)
def this(name : String, age : Int, gender : String){
this(name, age)

this.gender = gender
}
}


class Outer(val name: String) { outer =>
class Inner(val name: String){
def foo(b:Inner) = println("Outer: " + outer.name +
" Inner: " + b.name)
}

}
object OOPInScala{
def main(args: Array[String]) {

val outer1 = new Outer("Spark")
val outer2 = new Outer("Hadoop")
val inner1 = new outer1.Inner("Scala")
val inner2 = new outer2.Inner("Java")
inner1.foo(inner1);
inner2.foo(inner2);

// val p = new Teacher
// p.name = "Spark"
//
// p.sayHello

// val p = new Teacher("Spark", 5)
// println(" : " + p.age)

// val p = new Teacher("Spark", 5 , "male")
// println(" : " + p.age)


}


}

第8讲 构造器

原文:http://www.cnblogs.com/trgaaaaa/p/4735213.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!