Scala OO Example

scala 2016. 2. 1. 10:52

Scala를 이용해서 OO를 TEST.

(OO Test using Scala)

object Seminar{


class Dog(a:Int, n:String){
var age:Int = a
var name:String = n

def feed()={
println(this.name+ ":eating dog food")
}
}


class Cat(a:Int, n:String) extends Dog(a:Int, n:String){
override def feed()={
println(this.name+ ":eating Cat food")
}
}


//////// MAIN ////////////////////////////////////////////////
def main(args:Array[String]) = {
var allDog:Array[Dog] = Array( new Dog(1,"dogA"),
new Dog(2,"dogB"),
new Dog(3,"dogC"),
new Dog(4,"dogD"),
new Cat(5,"catA"))


for( dog<- allDog)
dog.feed()

}
} //end
Posted by yongary
,