Q1. Given the below Person.scala file with Person.calss, what will be the output?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
package com.sbthello //a class - you create instance of a class, which become objects class Person(name: String, age: Int, salary: BigDecimal) { println("This is printed when the object is created " + this) def calcBonus(bonus: BigDecimal) : BigDecimal = salary + bonus def getNameLength():Int = name.length() } object Test extends App { val person1 = new Person("John", 25, BigDecimal(250.00)) } |
A1. It prints the below text as when a Scala class is instantiated the statements in the body are executed after the object is constructed via the constructor defined in the class signature itself as “Person(name: String,
…
Read more ›