Scala类的get,set方法

package day02

import sun.management.Agent

class Student {
  //命名的时候不能和下面的set方法X_中的X重复,否则会出现二义性的异常
  private var ages = 0
  private var names = ""

  def age = ages

  //set方法必须要变量名_ 也就是age_
  def age_=(newAge: Int): Unit = {
    ages = newAge

  }
  //
  def name = names

  def name_=(newName: String): Unit = {
    names= newName

  }

}

 

你可能感兴趣的:(Scala)