Guest User

Point3D extends Point2D

a guest
Dec 7th, 2022
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.50 KB | Source Code | 0 0
  1. open class Point2D(
  2.     val x: Int,
  3.     val y: Int
  4. ) {
  5.     override fun hashCode(): Int = x + y
  6.  
  7.     override fun equals(other: Any?): Boolean =
  8.         other is Point2D &&
  9.         other.x == x &&
  10.         other.y == y
  11. }
  12.  
  13. class Point3D(
  14.     x: Int,
  15.     y: Int,
  16.     val z: Int
  17. ) : Point2D(x, y) {
  18.  
  19.     override fun hashCode(): Int = super.hashCode() + z
  20.  
  21.     override fun equals(other: Any?): Boolean =
  22.         super.equals(other) &&
  23.         other is Point3D &&
  24.         other.z == z
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment