Creating properties and methods

A class's members consist of properties (variable declarations) and methods (function declarations). You must declare all properties and methods inside the class body (the curly braces); otherwise, an error will occur during compilation.

Any variable declared within a class, but outside a function, is a property of the class. For example, the Person class discussed earlier has two properties, age and name, of type Number and String, respectively.

class Person {
  var age:Number;
  var name:String;
}

Similarly, any function declared within a class is considered a method of the class. In the Person class example, you created a single method called showInfo().

class Person {
  var age:Number;
  var name:String;
  function showInfo() {
    // showInfo() method definition
  }
}