class ClassDemo{
}
//主构造函数,constructor和init都可省略
class ClassDemo constructor(type:String){
init{
System.out.println(type)
}
}
class ClassDemo(type:String, var prop2: String = type){
var prop1 = type
}
class ClassDemo{
constructor(type:String){
System.out.println(type)
}
}
//包含主构造函数的二级构造函数
class ClassDemo(type:String){
constructor(type:String, param:String):this(type){
System.out.println(type + param)
}
}
class ClassDemo private constructor(){
}
var demo = ClassDemo("hello world")
val demo = ClassDemo("hello","world")
open class Base{
}
class SubClass : Base(){
}
//父类
open class Base(type:String){
}
//子类
class SubClass(type:String) : Base(type){
}
open fun funDemo() {}
override fun funDemo() {
super.funDemo()
}
open class SubClass : Base{
constructor(type:String) : super(type){
}
final override fun funDemo() {
super.funDemo()
}
}
//接口
interface InterfaceDemo{
fun funDemo(){}
}
//继承Base并且实现InterfaceDemo
class SubClass : Base(),InterfaceDemo{
final override fun funDemo() {
super<Base>.funDemo()
super<InterfaceDemo>.funDemo()
}
}
//密封类
sealed class Expr {
class Const(val number: Double) : Expr()
class Sum(val e1: Expr, val e2: Expr) : Expr()
object NotANumber : Expr()
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有