I am trying to work on overwrite function for toString inside Order class but it is not working

scala

#1

Doubts regarding Object oriented concepts(Classes):

I tried space,semicolon,colon,withoutspace but no luck.

Following all possibilities I tried :

scala> class order(orderid: Int,custid: Int,orderdate: String,orderstatus: String){
| override def toString=“order(orderid+custid+orderdate+orderstatus)”}
defined class order

scala> val o3=new order(5,6,“852”,“done”)
o3: order = order(orderid+custid+orderdate+orderstatus)

scala> var o3=new order(5,6,“852”,“done”)
o3: order = order(orderid+custid+orderdate+orderstatus)

scala> class order(orderid: Int,custid: Int,orderdate: String,orderstatus: String){
| override def toString=“order(orderid+”"+custid+""+orderdate+""+orderstatus)"}
:2: error: ‘;’ expected but string literal found.
override def toString=“order(orderid+”"+custid+""+orderdate+""+orderstatus)"}

scala> class order(orderid: Int,custid: Int,orderdate: String,orderstatus: String){
| override def toString=“order(orderid+”;"+custid+";"+orderdate+";"+orderstatus)"}
:12: warning: a pure expression does nothing in statement position; multiline expressions may require enclosing parentheses
override def toString=“order(orderid+”;"+custid+";"+orderdate+";"+orderstatus)"}

scala> class order(orderid: Int,custid: Int,orderdate: String,orderstatus: String){
| override def tostring=“order(orderid+” ,"+custid+" ,"+orderdate+" , “+orderstatus)”}
:2: error: ‘;’ expected but ‘,’ found.
override def tostring=“order(orderid+” ,"+custid+" ,"+orderdate+" , “+orderstatus)”}

Request your value inputs on this to understand this concept.

Thanks in advance.

Thanks,

Mahesh

9441033180


#3

Hi @Venkata_Mahesh
Try this below code

class order(var orderid: Int,var custid: Int,var orderdate: String,var orderstatus: String)
{
override def toString="order("+ orderid+" "+custid+" "+orderdate+" "+orderstatus+")"
}