Hello,
I am just starting to learn Kotlin and am practicing on Intellij - I am trying to make Dog objects from a class and am having a horrible time trying to figure out how to use fun main() with the class declaration.
Would someone explain to me please where I put the class methods and properties etc. when I using main(). I know there must be some logic behind this but I am tired of getting "Expecting member declaration". I would appreciate any help!
j
janvladimirmostert
11/12/2022, 8:54 PM
you could always put your fun main inside an object and the class if all you're doing is playing around
Copy code
object Blah {
class Dog { ... }
@JvmStatic
fun main(args: Array<String>) {
val dog = Dog()
}
}
this is even better
Copy code
class Dog { ... }
object Blah {
@JvmStatic
fun main(args: Array<String>) {
val dog = Dog()
}
}
s
Stephan Schroeder
11/14/2022, 11:16 AM
Copy code
fun main() {
val dog = Dog("Bello")
dog.bark()
}
class Dog(
val name: String,
) {
fun bark() {
println("wuff wuff")
}
}