Do you want BuboFlash to help you learning these things? Or do you want to add or correct something? Click here to log in or create user.



Tags
#odersky-programming-in-scala-2ed #scala
Question
Why won't this compile?

class Rational(n: Int, d: Int) { // This won’t compile
  require(d != 0)
  override def toString = n +"/"+ d
  def add(that: Rational): Rational =
  new Rational(n * that.d + that.n * d, d * that.d)
}
Answer
Because n and d can only be accessed in methods for this object - they seem to be captured like in closure for toString. They are not fields / members though

Tags
#odersky-programming-in-scala-2ed #scala
Question
Why won't this compile?

class Rational(n: Int, d: Int) { // This won’t compile
  require(d != 0)
  override def toString = n +"/"+ d
  def add(that: Rational): Rational =
  new Rational(n * that.d + that.n * d, d * that.d)
}
Answer
?

Tags
#odersky-programming-in-scala-2ed #scala
Question
Why won't this compile?

class Rational(n: Int, d: Int) { // This won’t compile
  require(d != 0)
  override def toString = n +"/"+ d
  def add(that: Rational): Rational =
  new Rational(n * that.d + that.n * d, d * that.d)
}
Answer
Because n and d can only be accessed in methods for this object - they seem to be captured like in closure for toString. They are not fields / members though
If you want to change selection, open document below and click on "Move attachment"

pdf

cannot see any pdfs

Summary

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

Details

No repetitions


Discussion

Do you want to join discussion? Click here to log in or create user.