Hello, I am just starting to learn Kotlin and am p...
# getting-started
p
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
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
Copy code
fun main() {
  val dog = Dog("Bello")
  dog.bark()
}

class Dog(
  val name: String,
) {
  fun bark() {
    println("wuff wuff")
  }
}
p
Thank you for the help!