Syntax

Kotlin Define a Class Syntax

In Kotlin, define a class: defines a class with a primary constructor — class Dog(val name: String)

Quick Answer

Syntax
class Dog(val name: String)
KotlinSyntax

Define a Class

Code example
class Dog(val name: String)

Defines a class with a primary constructor.

Learn More

How to define a class in Kotlin

  1. Open your Kotlin file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Kotlin Define a Class Syntax

Use class Dog(val name: String).

Related Syntax References

Frequently asked questions

What is the Kotlin syntax for define a class?

Use this pattern: class Dog(val name: String)

Can I copy this Kotlin code example?

Yes. Use Copy code and adapt the example to your program.

Is this Kotlin syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify