标签:string end get his ide over val pac getname
package com.jason.qianfeng abstract class Person(val gender: String) { val name: String val age: Int def getNamee: String def printlnP()= println(s"this is $name") } class Employee(val name: String, agex: Int, gen: String) extends Person(gen) { override def getNamee = this.name override val age = agex } object Person { def main(args: Array[String]): Unit = { val person = new Employee("jason", 23, "male") println(s"${person.name} : ${person.age},${person.gender}") } }
1.抽象类要加abstract 修饰
2.抽象类中可以定义抽象属性,方法,也可以定义具体的方法
3.实现类需要实现父类的抽象方法
4.可以直接将父类的抽象属性作为形参传给实现类,如class Employee(val name: String, agex: Int, gen: String)
标签:string end get his ide over val pac getname
原文地址:https://www.cnblogs.com/jason-dong/p/9503116.html