new tasks
This commit is contained in:
parent
2a4d27cea0
commit
80737d5a6a
1194 changed files with 15353 additions and 1 deletions
19
Task/Classes/Scala/classes.scala
Normal file
19
Task/Classes/Scala/classes.scala
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/**
|
||||
* 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
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue