Constructing class instance

Constructing a class instance is done using the new keyword, as follows:

var user = new User("Benjamin");

In this example, we create an instance of the User class. Doing so calls the class' constructor. The class constructor is defined in the class as the public non-static new function. It may take any number of parameters. The following is an example of our User class:

class User
{
public function new(title : String, name : String)
{
//Do things
}
}

You can call the superclass's constructor by calling super() (with parameters if needed).

You can access the current class instance using the this keyword.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.91.254