Question | Click to View Answer |
What does the following code print? class User(n: String) {
val name: String = n
}
var u = new User(n = "Frank")
println(u.name)
|
The |
What does the following code print? class Carrot(val flavor: String)
var c = new Carrot(flavor = "weird")
println(c.flavor)
|
The |
What does the following code print? class Cat(val name: String) {
def greet: String = {
s"My name is $name"
}
}
var myCat = new Cat(name = "darla")
println(myCat.greet)
|
The |
What does the following code print? class Singer(var alias: String)
var singers = List(
new Singer("miley"),
new Singer("bradley")
)
println {
singers map(_.alias)
}
|
The The println {
singers.map { (s: Singer) =>
s.alias
}
}
|
What does the following code print? class A {
def hi = "Hello from A"
}
class B extends A
var bInstance = new B
println {
bInstance.hi
}
|
Class |
What does the following code print? class Tree {
def about = "I am made of wood"
}
class Pine extends Tree {
override def about = super.about + " and sticky!"
}
var aPine = new Pine
println(aPine.about)
|
The The
The string |
What does the following code print? class Mango(var status: String) {
def updateStatus(s: String): Unit = {
status = s
}
}
var myMango = new Mango("ripe")
println(myMango.status)
myMango.updateStatus("rotten")
println(myMango.status)
|
The following strings are printed: ripe
rotten
The |
What does the following code print? class Kitchen(color: String, floorType: String = "tile") {
def describe = {
s"The kitchen has $floorType floors"
}
}
var myKitchen = new Kitchen("purple")
println(myKitchen.describe)
|
The
|
Define a |
class Person(firstName: String, lastName: String) {
def fullName = {
s"$firstName $lastName"
}
}
var bob = new Person("bob", "loblaw")
println(bob.fullName)
The |