Home »
MCQs »
Scala MCQs
The output of the following block of code is | Scala Question 5
51. The output of the following block of code is -
class Student{
var roll = 43;
def printTotal(){
var totalMarks = 500
println(roll)
}
}
object MyClass{
def main(args:Array[String]) {
var s1 = new Student
println(s1.totalMarks)
}
}
- 500
- 43
- Error
- None of these
Answer: C) Error
Explanation:
totalMarks is a local variable of printTotal() method. Hence, cannot be used outside it.