TheBulgarianWolf

Overriding Member Function

Apr 4th, 2021
441
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. open class Personn(){
  2.     open fun displayAge(age:Int){
  3.         println("My age is $age")
  4.     }
  5. }
  6.  
  7. class Girl : Personn(){
  8.     override fun displayAge(age: Int) {
  9.         super.displayAge(age)
  10.         println("My fake age is ${age-5}")
  11.     }
  12. }
  13.  
  14. fun main(args: Array<String>){
  15.     val girl = Girl()
  16.     girl.displayAge(35)
  17. }
RAW Paste Data