Advertisement
rangga_hrdme

OOP: CLASS, OVERLOADING

Apr 20th, 2021
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.50 KB | None | 0 0
  1. // CLASS: OVERLOADING
  2. class vehicles {
  3.     // SET PROPERTIES
  4.     var name: String? = null
  5.     var wheels: String? = null
  6.     var wing: Int? = null
  7.     var color: String? = null
  8.  
  9.     constructor()
  10.  
  11.     // Constructor
  12.     constructor(name: String, wheels: String, wing: Int, color: String) : this() {
  13.         this.name = name
  14.         this.wheels = wheels
  15.         this.wing = wing
  16.         this.color = color
  17.  
  18.         println("OBJECT, Name: " + this.name + " wheels: " + this.wheels + " wing: " + this.wing + " color: " + this.color)
  19.     }
  20.  
  21.     constructor(name: String, wheels: String, color: String) : this() {
  22.         this.name = name
  23.         this.color = color
  24.         this.wheels = wheels
  25.  
  26.         println("OBJECT, Name: " + this.name + " wheels: " + this.wheels + " color: " + this.color)
  27.     }
  28.  
  29.     constructor(name: String, color: String, wing: Int) : this() {
  30.         this.name = name
  31.         this.color = color
  32.         this.wing = wing
  33.  
  34.         println("OBJECT, name: " + this.name + " wing: " + this.wing + " color: " + this.color)
  35.     }
  36.  
  37.     constructor(name: String, color: String) : this() {
  38.         this.name = name
  39.         this.color = color
  40.  
  41.         println("OBJECT, Name: " + this.name + " color: " + this.color)
  42.     }
  43. }
  44.  
  45. fun main() {
  46.  
  47.     var jet = vehicles("jet", "3", 2, "dark blue")
  48.     var truck = vehicles("truck", "8", "yellow")
  49.     var bike = vehicles("bike", "black")
  50.     var plane = vehicles("plane", "black", 6)
  51.     var rocket = vehicles("rocket", "white", 2)
  52. }
  53.  
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement