Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. class Point(xc: Int = 1, yc: Int = 2) {
  2. var _x: Int = xc
  3. var _y: Int = yc
  4. def getInstance: this.type = this
  5.  
  6. def x: Int = _x
  7. def x_=(newX: Int): this.type = {
  8. _x = newX
  9. this
  10. }
  11.  
  12. def y: Int = _y
  13. def y_=(newY: Int): this.type = {
  14. _y = newY
  15. this
  16. }
  17. }
  18.  
  19. class Circle(xc: Int = 1, yc: Int = 2, rc: Int = 3) extends Point(xc, yc) {
  20. var _r: Int = rc
  21.  
  22. def r: Int = _r
  23. def r_=(newR: Int): this.type = {
  24. _r = newR
  25. this
  26. }
  27.  
  28. }
  29.  
  30. class Cylinder(xc: Int = 1, yc: Int = 2, rc: Int = 3, hc: Int = 4)
  31. extends Circle(xc, yc, rc) {
  32. var _h: Int = hc
  33.  
  34. def h: Int = _h
  35. def h_=(newH: Int): this.type = {
  36. _h = newH
  37. this
  38. }
  39. }
  40.  
  41. val cyl = new Cylinder(1, 2)
  42. val cir = new Circle(1, 2, 3)
  43. val poi = new Point(1, 2)
  44.  
  45. poi.getInstance
  46. cir.getInstance
  47. cyl.getInstance
  48.  
  49. cyl.x = 2
  50. cyl.r = 11
  51. cyl.h = 1
  52. cir.r = 4
  53. cir.y = 12
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement