Advertisement
Guest User

Untitled

a guest
Dec 15th, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.33 KB | None | 0 0
  1. //9.1
  2. //a)
  3. class Time(private[this] var h:Int){
  4.     if(h<0) h=0
  5.     def hour: Int = h //getter
  6.     def hour_=(x: Int) { //setter
  7.         if(x>0) h=x
  8.         else h=0
  9.     }
  10.  
  11.   object Time{
  12.       def apply(h:Int) = new Time(h)
  13.   }
  14. }
  15.  
  16. // i teraz wywoluje:
  17. // val g=Time(-3)
  18. // i czy nie powinno wyrzucic g:Time=0?
  19. // wychodzi mi g:Time=-3, dlaczego
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement