Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Point(xc: Int = 1, yc: Int = 2) {
- var _x: Int = xc
- var _y: Int = yc
- def getInstance: this.type = this
- def x: Int = _x
- def x_=(newX: Int): this.type = {
- _x = newX
- this
- }
- def y: Int = _y
- def y_=(newY: Int): this.type = {
- _y = newY
- this
- }
- }
- class Circle(xc: Int = 1, yc: Int = 2, rc: Int = 3) extends Point(xc, yc) {
- var _r: Int = rc
- def r: Int = _r
- def r_=(newR: Int): this.type = {
- _r = newR
- this
- }
- }
- class Cylinder(xc: Int = 1, yc: Int = 2, rc: Int = 3, hc: Int = 4)
- extends Circle(xc, yc, rc) {
- var _h: Int = hc
- def h: Int = _h
- def h_=(newH: Int): this.type = {
- _h = newH
- this
- }
- }
- val cyl = new Cylinder(1, 2)
- val cir = new Circle(1, 2, 3)
- val poi = new Point(1, 2)
- poi.getInstance
- cir.getInstance
- cyl.getInstance
- cyl.x = 2
- cyl.r = 11
- cyl.h = 1
- cir.r = 4
- cir.y = 12
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement