extends 与Java一样,也是使用extends关键字,使用继承可以有效复用代码 class Person { private var name = "leo" def getName = name } class Student extends Person { private var score = "A" def getScore = score } defined class Person defined class Student scala>…
定义类 // 定义类,包含field以及method class HelloWorld { private var name = "Leo" def sayHello() { println("Hello" + name)} def getName = name } defined class HelloWorld // 创建类对象,并调用其方法 scala> val helloworld = new HelloWorld helloworld: HelloW…