YogenGhodke
6/11/2019 - 6:37 PM

Constructors and Classes

class Student(var name: String = "Yogen", var age: Int)   // Declare Variables to be used in the Constructor here
{
    init                                    
    {
        println("Student: $name");              // Write Constructor Code in this Block
        println("Age: $age");
    }
    
    // To give user another way of declaring object, use secondary constructor
    
    constructor (student_number: Int): this(name: "Yogen")
        {
            // Write init statements here
        }
    
    var some = 7;                               // Write Class contents here
    fun disp()
        {
            print(some);
        }
}

fun main()
{
    val object1 = Student("abc", 14);           //Object Declaration
    val object2 = Student(60);                  // Calls other Constructor
    object1.disp();                             // Fn Call through Object
}