码迷,mamicode.com
首页 > 其他好文 > 详细

《快学scala》Chapter 5 类

时间:2018-01-11 15:41:51      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:person   this   typename   count   draw   mount   first   post   位置   

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 类

标签:person   this   typename   count   draw   mount   first   post   位置   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!