Question: NEED ALL QUESTIONS ANSWERED Question 2: Select all Scala programs from the list given below that will produce an error message from the Scala interpreter.
NEED ALL QUESTIONS ANSWERED

Question 2:
Select all Scala programs from the list given below that will produce an error message from the Scala interpreter.
For technical reasons, you must assume that each of these programs is run inside a freshly initialized interpreter environment.
Select one or more:
a.
val x = "Hello" val y = 10 val z = x + y println(z)
b.
def hello(x: String): String = { "World" } c.
val x = "Hello" x = "World" print(x)
d.
val a = b val b = a println( a + b )
e.
class MyPreciousObject (x: Int, y: String) { def returnXY() = x + y } val z = new MyPreciousObject("Hello", 20 ) z.returnXY()Question 3:
def foo(x: Int): Int = x + 2 def bar(y: String): String = "Hello" + y def baz(z: String): Int = { val str1 = bar(z) val siz1 = str1.size foo(siz1) } Which of the following statements about these functions are true?
Select one or more:
a. The value siz1 in baz will have the type String
b. Although foo's argument x is typed to be an Int, scala will correctly execute a call such as foo("World")
c. Calling foo(bar(z)) will result in a type mismatch error because the output type of bar (String) is not the same as the input type of foo (Int).
d. Changing the last statement of baz from
foo(siz1)
to
return foo(siz1)
does not change its meaning.
e. baz takes in an input string and returns the number equaling the size of input string plus 7.
Question 4:
Consider the scala loop below:
for (iHow many times will it run?
Answer:
Question 3:
Consider the scala loop below:
for (iHow many times will it run?
Answer:
Question 5:
Consider the scala loop below:
for (iHow many times will the loop run?
Answer:
Question 1 Consider the class below. Not complete Marked out of 3.00 Flag question class BarkingDog(val name: String, val breed:String, val age: Int ) { /* A list of shouts for the dog */ val listofShouts = List("Wuff Wuff", "Bow Wow Wow", "ARuff ARuff", "Rwoff", "Meow") /* The current shout */ private var idx = 0 def bark() = { /* Print the bark */ println(s"${this.name}, a proud ${this.breed) says ${listofShouts(idx)}!") /* Increment the index but wrap around to o to avoid embarassing exceptions */ this.idx = (this.idx + 1) %(listofShouts.length) /* This is only possible because } Identify each member of the class with the attributes that apply to it. bark Choose... name Choose.. + breed Choose... - idx Choose
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
