Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

method calling using classes in scala

Tags:

scala

I am trying to run this program but it is telling me that r is not found. How do you call the method since it is in a class? (I am assuming that the error is because of this)

package pack

class Sud(val grid: List[List[Int]]) {

  def r(r: Int): List[Int] =
  //code
}

object Sud
{
  def main(args: Array[String]) 
  {

     val puzzle=new Sudoku(List(
          List(0, 0, 9, 0, 0, 7, 5, 0, 0),
        //rest of Sudoku puzzle created by repeating the above statement

          println(r(0)) //ERROR given here
  }
}
like image 443
user2947615 Avatar asked Mar 24 '26 11:03

user2947615


1 Answers

As said in the comments, in your code r is a class method. Hence you need to Instantiate your Class Sud in order to call that method.

val inst: Sud = new Sud(puzzle)

println(inst.r(0))
like image 135
abronan Avatar answered Mar 27 '26 04:03

abronan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!