You have created a data class, Point, that holds two properties, x and y, representing a point on a grid. You want to use the hash symbol for subtraction on the Point class, but the code as shown will not compile. How can you fix it?kotlindata class Point(val x: Int, val y: Int)operator fun Point.plus(other: Point) = Point(x + other.x, y + other.y)operator fun Point.hash(other: Point) = Point(x - other.x, y - other.y)fun main() { val point1 = Point(10, 20) val point2 = Point(20, 30) println(point1 + point2) println(point1 # point2)}

🎲 Try a Random Question  |  Total Questions in Quiz: 83  |  🧠 Study this quiz with Flashcards
This question is part of a full practice quiz:
Kotlin Quiz — practice the complete quiz, review flashcards, or try a random question.

Kotlin MCQs For LinkedIn Skill Assessments.


You have created a data class, Point, that holds two properties, x and y, representing a point on a grid. You want to use the hash symbol for subtraction on the Point class, but the code as shown will not compile. How can you fix it?<br>kotlin<br>data class Point(val x: Int, val y: Int)<br>operator fun Point.plus(other: Point) = Point(x + other.x, y + other.y)<br>operator fun Point.hash(other: Point) = Point(x - other.x, y - other.y)<br>fun main() {<br> val point1 = Point(10, 20)<br> val point2 = Point(20, 30)<br> println(point1 + point2)<br> println(point1 # point2)<br>}<br>