zoukankan      html  css  js  c++  java
  • scala面向对象编程

    //scala 中简单的类的实例化调用

    object test { def main(args: Array[String]): Unit
    = { val hello=new student hello.increase() println(hello.fun()) } class student{ private var age=18 val name="stenven" def increase()=age+=1 def fun()=age } }
    class student{
      private  var age=18
      private  var name= ""
      private var classNum=1
    
      def this(name:String){
        this()
        this.name=name
      }
      def this(name:String,classNum:Int){
        this(name)
        this.classNum=classNum
      }
    
      def  increase(step:Int)={age+=step}
      def current()={age}
      def info()={
        printf("name:%s and classNum is %d
    ",name,classNum)
      }
    }
    
    object TestStudent_02{
      def main(args: Array[String]): Unit = {
        val myStudent1=new student
        val myStudent2=new student("zhang san")
        val myStudent3=new student("Lisi,75")
        myStudent1.info()
        myStudent1.increase(1)
        printf("11111111111Current age is: %d
    ",myStudent1.current())
        println()
    
    
        myStudent2.info()
        myStudent2.increase(2)
        printf("2222222222222Current age is: %d
    ",myStudent2.current())
       println()
    
        myStudent3.info()
        myStudent3.increase(2)
        printf("333333333333Current age is: %d
    ",myStudent3.current())
    
      }
    }
    RUSH B
  • 相关阅读:
    IDETalk
    servlet概述
    过滤器(Filter)
    ieda常用快捷键
    UUID
    JRebel 7.0.10 for intellij IDEA 2017.1
    BP神经网络(手写数字识别)
    遗传算法解决TSP问题
    [CODEVS1258]关路灯
    [NOIP2007]统计数字
  • 原文地址:https://www.cnblogs.com/tangsonghuai/p/11283000.html
Copyright © 2011-2022 走看看