5. 3.1.1 クラス定義
これが Person クラスの定義です。
class Person {
val firstName = "Noel"
val lastName = "Welsh"
def name = firstName + " " + lastName
}
オブジェクト宣言のようにクラス宣言は名前を束縛します。しかし、クラス名は式で利用
できません。クラスは値ではなく、違う名前空間に存在しています。
Person
// error: not found: value Person
// Person
// ^
6.
7. 3.1.1 クラス定義
new 演算子を使用して新しい Person オブジェクトを作成できます。いつもの方法でメ
ソッドとフィールドにアクセスできます。
val noel = new Person
// noel: Person = Person@3235186a
noel.firstName
// res: String = Noel
8.
9. 3.1.1 クラス定義
オブジェクトの型は Person です。new 呼び出しごとに、同じ型で別個のオブジェクトが
生成されます。
noel
// res: Person = Person@3235186a
val newNoel = new Person
// newNoel: Person = Person@2792b987
val anotherNewNoel = new Person
// anotherNewNoel: Person = Person@63ee4826