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)
	}
}
  1. 500
  2. 43
  3. Error
  4. None of these

Answer: C) Error

Explanation:

totalMarks is a local variable of printTotal() method. Hence, cannot be used outside it.

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.