Interview Questions
Kotlin
Q1: What is a primary constructor in Kotlin? ☆☆
Answer: The primary constructor is part of the class header. Unlike Java, you don't need to declare a constructor in the body of the class. Here's an example:
package es.cloudey.pagespeed.util; | |
import java.util.HashMap; | |
import java.util.Map; | |
import android.os.Bundle; | |
import android.os.Parcelable; | |
public class CollectionUtils { | |
public static Bundle toBundle(Map<String, ? extends Parcelable> input) { |
Answer: The primary constructor is part of the class header. Unlike Java, you don't need to declare a constructor in the body of the class. Here's an example: