标签:增加 imp 方法 就是 int img its array 图片
1、scala的嵌套类也成为内部类
package com.itstar.scala.test
import scala.collection.mutable.ArrayBuffer
class Student2 {
private var stuName:String = "Tom"
private var stuAge:Int = 20
//定义一个容纳课程的数组
private var courseList = new ArrayBuffer[course]()
//声明一个增加课程的方法
def addCourse(cname:String,cgrade:Int) = {
var c = new course(cname,cgrade)
courseList += c
}
//定义课程类,使用主构造器,就是把属性写在类名后面
//var courseName:String,var grade:Int等同于private var xxx
class course(var courseName:String,var grade:Int){}
}
object Student2{
def main(args: Array[String]): Unit = {
var s1 = new Student2
s1.addCourse("语文",90)
s1.addCourse("数学",100)
s1.addCourse("英语",55)
println("姓名:" + s1.stuName + "\t" + "年龄:" + s1.stuAge)
println("=============课程成绩=============")
for(s <- s1.courseList){
println(s.courseName+"\t"+s.grade)
}
}
}
标签:增加 imp 方法 就是 int img its array 图片
原文地址:https://www.cnblogs.com/jeff190812/p/11823681.html