을 얻는 것은 여기가 class
Subjects
하지만 점점 컴파일 오류에 유효한 방법이다 addSubject
를 호출하는 것을 시도하고있다클래스에서 메서드를 호출 할 수 없습니다. 런타임 오류
scala> class Subjects {
| //The default Access Modifier of a vairable is 'public' #101
| private var subjects:List[String] = Nil
|
| //Always Specify Return type for Readability #103
| //Here we are using Cons operator to prepend (Constant time)
| //A method with Side effect is also called 'Procedure' #103
| def addSubject(subject: String):Unit = { subjects = subject :: subjects }
|
| def getSubjects():List[String] = subjects
| }
defined class Subjects
scala>
scala> val obj = new Subjects
obj: Subjects = [email protected]
scala> obj.addSubject("Math")
<console>:47: error: value addSubject is not a member of Subjects
obj.addSubject("Math")
내 코드입니다. 내가 여기서 무엇을 놓치고 있니?
저에게 잘 맞습니다. – Ryan