fcamuso

Kotlin video 25

Aug 17th, 2025
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.83 KB | None | 0 0
  1. import java.io.File
  2. import java.io.FileWriter
  3. import java.io.InvalidObjectException
  4. import javax.management.ImmutableDescriptor
  5. import kotlin.random.Random
  6.  
  7. open class Arma(var nome: String = "none",  protected var dannoBase: Int = 1) {
  8.  
  9.     init { require(dannoBase>=0) }
  10.  
  11.     fun spara() {
  12.         println("Danno cinetico: $dannoBase")
  13.     }
  14. }
  15.  
  16. class ArmaElettrica(nome: String = "none",  dannoBase: Int = 1, var livelloDannoElementale: Int = 1)
  17.     : Arma(nome, dannoBase) {
  18.  
  19.         init {
  20.             require(livelloDannoElementale in 1..5)
  21.         }
  22.  
  23.     fun metodoClasseFiglia() {
  24.         println(dannoBase)
  25.     }
  26.     }
  27.  
  28.  
  29. fun main() {
  30.  
  31.     val unArmaElettrica = ArmaElettrica("Folgorator", 80, 3)
  32.  
  33.     println("${unArmaElettrica.nome} ${unArmaElettrica.metodoClasseFiglia()}" )
  34.     unArmaElettrica.spara()
  35. }
Advertisement
Add Comment
Please, Sign In to add comment