直接上代码:
package com.test.scalaw.test.demo
/**
* scala定义多个构造函数,
* 另外,Scala中有只有一个主要构造函数,其他都是辅助构造函数。而且需要注意的是,辅助构造函数必须调用主构造函数或者通过this(…)之间相互调用
*/
class Point(x:Int,y:Int) {
var x1:Int =
x
var y1:Int =
y
def this(xc:Int) {
this(xc,0)
//这个必须要
println("我是构造函数"
)
}
override def toString(): String = "(" + x + ", " + y + ")"
}
转载于:https://www.cnblogs.com/huzi007/p/6210364.html
相关资源:JAVA上百实例源码以及开源项目