Time for an 2014 update…
This commit is contained in:
parent
372c577f83
commit
09687c4926
2520 changed files with 34227 additions and 7318 deletions
25
Task/Call-an-object-method/Scala/call-an-object-method.scala
Normal file
25
Task/Call-an-object-method/Scala/call-an-object-method.scala
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/** This class implicitly includes a constructor which accepts an Int and
|
||||
* creates "val variable1: Int" with that value.
|
||||
*/
|
||||
class MyClass(val variable1: Int) {
|
||||
var variable2 = "asdf" // Another instance variable; a public var this time
|
||||
def this() = this(0) // An auxilliary constructor that instantiates with a default value
|
||||
def myMethod = variable1 // A getter for variable1, getter of variable1 is auto-created
|
||||
}
|
||||
|
||||
object HelloObject {
|
||||
val s = "Hello" // Not private, so getter auto-generated
|
||||
}
|
||||
|
||||
/** Demonstrate use of our example class.
|
||||
*/
|
||||
object Call_an_object_method extends Application {
|
||||
val s = "Hello"
|
||||
val m = new MyClass()
|
||||
val n = new MyClass(3)
|
||||
|
||||
println(HelloObject.s) // prints "Hello" by object getterHelloObject
|
||||
|
||||
println(m.myMethod) // prints 0
|
||||
println(n.myMethod) // prints 3
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue