Overriding mutable variable in child class in Scala -


i have abstract class , child class extends

abstract class user{ var name : string =  "test" } 

i have class

class student(name : string) extends user{  } 

now whenever try pass name making object of student , prints value on console instead of showing me name passed in constructor shows test parent class

object main extends app{   val st = new student("ahsen")   var name = st.name    println("name " + name)  } 

it outputs

name test

please help

you can't override var. maybe assign it?

class student(n: string) extends user {   name = n } 

alternatively can define name var in student, if superclass declares variable, not defining it:

abstract class user {   var name: string } class student(var name: string) extends user 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -