Scala-- nested class

1, scala also become nested class inner class

com.itstar.scala.test Package 

Import scala.collection.mutable.ArrayBuffer

class STUDENT2 {
Private stuname var: String = "Tom"
Private stuAge var: Int = 20 is
// define a receiving array course
private var courseList = new ArrayBuffer [ course] ()
// declare a method of increasing program
DEF the addCourse (CNAME: String, cgrade: Int) = {
var C = new new course (CNAME, cgrade)
courseList = C +
}

// class defined course, the use of the primary constructor is written in the property after the class name
// var courseName: String, var grade : Int equivalent var XXX Private
class Course (var CourseName: String, var Grade: Int) {}
}

Object STUDENT2 {
DEF main (args: the Array [String]): Unit = {
var new new S1 = STUDENT2
s1.addCourse ( "Chinese", 90)
s1.addCourse ( "mathematics", 100)
s1.addCourse ( "English", 55)
println ( "Name:" + s1.stuName + "\ t " + " Age:" + s1.stuAge)
println ( "== =========== course grade ============= ")
for (S <- s1.courseList) {
the println (s.courseName +" \ T "+ S. Grade)
}
}
}

 

Guess you like

Origin www.cnblogs.com/jeff190812/p/11823681.html