Reputation: 26008
Suppose I have a class
class MyClass(a: Int, b: String) {
//....
}
If I want to add some custom logic (code) to this constructor, how do I do that?
Upvotes: 4
Views: 1524
Reputation: 11366
class MyClass(a: Int, b: String) {
// this is the constructor right here
println("Hi, i'm the constructor")
def imAMethod = 1
println("Hi, I'm also part of the constructor down here, the whole class body is")
}
Upvotes: 17