March 2014 update

This commit is contained in:
Ingy döt Net 2014-04-02 16:56:35 +00:00
parent 09687c4926
commit a25938f123
1846 changed files with 21876 additions and 5203 deletions

View file

@ -1,19 +1,24 @@
/**
* This class implicitly includes a constructor which accepts an int and
* creates "val variable1: Int" with that value.
/** This class implicitly includes a constructor which accepts an Int and
* creates "val variable1: Int" with that value.
*/
class MyClass(variable1: Int) {
var variable2 = "asdf" // Another instance variable; a var this time
def this() = this(0) // An auxilliary constructor that instantiates with a default value
def myMethod = variable1 // A getter for variable1
class MyClass(val myMethod: Int) { // Acts like a getter, getter automatically generated.
var variable2 = "asdf" // Another instance variable; a public var this time
def this() = this(0) // An auxilliary constructor that instantiates with a default value
}
/**
* Demonstrate use of our example class.
*/
object Main extends Application {
val m = new MyClass()
val n = new MyClass(3)
println(m.myMethod) // prints 0
println(n.myMethod) // prints 3
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)
println(HelloObject.s) // prints "Hello" by object getterHelloObject
println(m.myMethod) // prints 0
println(n.myMethod) // prints 3
}