Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
24
Task/Call-an-object-method/Scala/call-an-object-method.scala
Normal file
24
Task/Call-an-object-method/Scala/call-an-object-method.scala
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/* This class implicitly includes a constructor which accepts an Int and
|
||||
* creates "val variable1: Int" with that value.
|
||||
*/
|
||||
class MyClass(val memberVal: Int) { // Acts like a getter, getter automatically generated.
|
||||
var variable2 = "asdf" // Another instance variable; a public mutable this time
|
||||
def this() = this(0) // An auxilliary constructor that instantiates with a default value
|
||||
}
|
||||
|
||||
object HelloObject {
|
||||
val s = "Hello" // Not private, so getter auto-generated
|
||||
}
|
||||
|
||||
/** Demonstrate use of our example class.
|
||||
*/
|
||||
object Call_an_object_method extends App {
|
||||
val s = "Hello"
|
||||
val m = new MyClass
|
||||
val n = new MyClass(3)
|
||||
|
||||
assert(HelloObject.s == "Hello") // "Hello" by object getterHelloObject
|
||||
assert(m.memberVal == 0)
|
||||
assert(n.memberVal == 3)
|
||||
println("Successfully completed without error.")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue