首页 > 其他 > 详细

《快学scala》Chapter 5 类

时间:2018-01-11 13:04:11      阅读:187      评论:0      收藏:0      [点我收藏+]
package c5

class Counter {
  private var value = 0
  def increment(){
    if(value < Int.MaxValue){
      value += 1
    }
  }
  def current() = value
}
class BankAccount{
  val balance = 0
  def deposit(amount:Double){}
  def withdraw(){}
}
class Time(val hours:Int,val minutes:Int){
  def before(other:Time):Boolean = {
    hours < other.hours || (hours == other.hours && minutes < other.minutes)
  }
  override def toString: String = {hours + ":" + minutes}
}
class Time1(val hours:Int,val minutes:Int){
  def before(other:Time):Boolean = {
    hours < other.hours || (hours == other.hours && minutes < other.minutes)
  }
  override def toString: String = {hours * 60 + minutes + ""}
}
import java.beans.BeanProperty

import scala.beans.BeanProperty/*查找包位置*/
class Student{
  @BeanProperty var name:String = _
  @BeanProperty var id:Long = _
}
/*p06*/
class Person(var age:Int){age = if(age < 0)0 else age}
/*p07*/
class Person1(val name:String){
  val (firstname,lastname) = name.split(" ")
}
/*p08*/
class Car(val maker:String,val typename:String){
  private var typeyear:Int = -1
  private var Board:String = ""
  def this(maker:String,typename:String,typeyear:Int,Board:String){
    this()
    this.typeyear=typeyear
    this.Board=Board
  }
}
/*p10*/
class Employ(){
  val name:String = "John Q.Public"
  var salary:Double = 0.0
}

  

《快学scala》Chapter 5 类

原文:https://www.cnblogs.com/AryaStark/p/8267511.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!