Vidyalelo
Computer Science · Q282

Kotlin Programming MCQ for Competitive Exams, Interviews, and Certifications

Engineering and GATE · Computer Science · question 282

Q282

Why does not this code snippet compile? class Cat (name: String) fun greet() println("Hello this.name") fun main() val thunderCat = Cat("ThunderCat") thunderCat.greet()

A.
Because name is a class parameter, not a property-it is unresolved main().
Answer
B.
In order to create an instance of a class, you need the keyword new
C.
The reference to name needs to be scoped to the class, so it should be this.name
D.
Classes cannot be immutable. You need to change var to val

Answer: Option A

Solution

Answer: Option A
No explanation is given for this question Let's Discuss on Board