Notes on Scala’s class :
- Parameters of Scala methods are values (val) not variables (var)
- Scala method returns the last value computed by the method
// Scala class with a private member
class Shape{
private var vertexes = 0
}
// Scala class with a method
class Shape{
def draw() : Unit = {
// Body of the method
}
}
// Scala class with a method with a return type and constructor
class Shape{
def Shape() = {
vertexes = 0
}
def draw():Unit = {
}
def getVertexes(): Int = {
return vertexes
}
private var vertexes = 0
}
Reference :