-
Notifications
You must be signed in to change notification settings - Fork 1
/
Class_builder.sc
36 lines (27 loc) · 1.26 KB
/
Class_builder.sc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import scala.beans.BeanProperty
import scala.collection.mutable.ArrayBuffer
object Class_builder {
println("Welcome to the Scala worksheet") //> Welcome to the Scala worksheet
class network {
println("this is new network")
class Member( val name: String){
println("new contacts created")
val contacts = new ArrayBuffer[Member]
}
private val members = new ArrayBuffer[Member]
def join(name: String): Member={
val m = new Member(name)
m.contacts += m
m
}
}
val Chatter = new network //> this is new network
//| Chatter : Class_builder.network = Class_builder$network$1@341b80b2
val MyFace = new network //> this is new network
//| MyFace : Class_builder.network = Class_builder$network$1@55a1c291
val Fred = Chatter.join("Fred") //> new contacts created
//| Fred : Class_builder.Chatter.Member = Class_builder$network$1$Member@2890c4
//| 51
//Chatter.members
println(Fred.contacts) //> ArrayBuffer(Class_builder$network$1$Member@2890c451)
}