<h3><strong style="font-size: inherit; background-color: rgb(255 255 255 / var(--tw-bg-opacity));">Classes and Objects</strong></h3><ul><li><strong>Classes</strong>: A blueprint for creating objects. They define properties (variables) and behaviors (functions).<ul><li>Syntax:<pre class="!overflow-visible"><div class="contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950"><div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-kotlin"><span class="hljs-keyword">class</span> <span class="hljs-title class_">Person</span> {
    <span class="hljs-keyword">var</span> name: String = <span class="hljs-string">""</span>
    <span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">greet</span><span class="hljs-params">()</span></span> {
        println(<span class="hljs-string">"Hello, <span class="hljs-variable">$name</span>!"</span>)
    }
}
</code></div></div></pre></li></ul></li><li><strong>Objects</strong>: Instances of a class. Created using the <code>Person()</code> syntax.<ul><li>Example:<pre class="!overflow-visible"><div class="contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950"><div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-kotlin"><span class="hljs-keyword">val</span> person = Person()
person.name = <span class="hljs-string">"Alice"</span>
person.greet() <span class="hljs-comment">// Outputs: Hello, Alice!</span>
</code></div></div></pre></li></ul></li></ul><h4><strong>Constructors</strong></h4><ul><li><p><strong>Primary Constructor</strong>: Declared in the class header to initialize properties.</p><ul><li>Example:<pre class="!overflow-visible"><div class="contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950"><div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-kotlin"><span class="hljs-keyword">class</span> <span class="hljs-title class_">Person</span>(<span class="hljs-keyword">val</span> name: String, <span class="hljs-keyword">var</span> age: <span class="hljs-built_in">Int</span>)
</code></div></div></pre>Usage:<pre class="!overflow-visible"><div class="contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950"><div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-kotlin"><span class="hljs-keyword">val</span> person = Person(<span class="hljs-string">"Alice"</span>, <span class="hljs-number">25</span>)
println(person.name) <span class="hljs-comment">// Outputs: Alice</span>
</code></div></div></pre></li></ul></li><li><p><strong>Secondary Constructor</strong>: Defined inside the class using <code>constructor</code> keyword for additional initialization logic.</p><ul><li>Example:<pre class="!overflow-visible"><div class="contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950"><div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-kotlin"><span class="hljs-keyword">class</span> <span class="hljs-title class_">Person</span> {
    <span class="hljs-keyword">var</span> name: String
    <span class="hljs-keyword">var</span> age: <span class="hljs-built_in">Int</span>

    <span class="hljs-keyword">constructor</span>(name: String, age: <span class="hljs-built_in">Int</span>) {
        <span class="hljs-keyword">this</span>.name = name
        <span class="hljs-keyword">this</span>.age = age
    }
}
</code></div></div></pre></li></ul></li><li><p><strong>Initialization Block (<code>init</code>)</strong>: Executes after the primary constructor for extra logic.</p><ul><li>Example:<pre class="!overflow-visible"><div class="contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950"><div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-kotlin"><span class="hljs-keyword">class</span> <span class="hljs-title class_">Person</span>(<span class="hljs-keyword">val</span> name: String, <span class="hljs-keyword">var</span> age: <span class="hljs-built_in">Int</span>) {
    <span class="hljs-keyword">init</span> {
        println(<span class="hljs-string">"Person created with name: <span class="hljs-variable">$name</span>"</span>)
    }
}
</code></div></div></pre></li></ul></li></ul><h4><strong>Object Declaration</strong></h4><ul><li>Use the <code>object</code> keyword to create a singleton object.<ul><li>Example:<pre class="!overflow-visible"><div class="contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950"><div class="overflow-y-auto p-4" dir="ltr"><code class="!whitespace-pre hljs language-kotlin"><span class="hljs-keyword">object</span> Logger {
    <span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">log</span><span class="hljs-params">(message: <span class="hljs-type">String</span>)</span></span> {
        println(<span class="hljs-string">"Log: <span class="hljs-variable">$message</span>"</span>)
    }
}
Logger.log(<span class="hljs-string">"Hello!"</span>) <span class="hljs-comment">// Outputs: Log: Hello!</span>
</code></div></div></pre></li></ul></li></ul><p>These concepts are the foundation of building reusable and modular Kotlin applications.</p>