# How to make an object of a class

- How to make an object of a class
  - The Program
  - The Code:
    - Fmain.class:
    - CCar.class
  - The Source

You can define classes. A class is a kind of template, it is not used directly. To use it, a copy of it is made. This copy is called an object. You can make different objects of the same class.
A class is a datatype, so the declaration of the object looks like a normal declaration of a variable:
object_name AS Class_name
but an object has to be instantiated with NEW:
object_name = NEW Class_name
You can "recycle" your classes in different projects.
The class CCar.class, which is used here, is used in the following chapters also:
How to make more objects of a class.

## The Program

If the button is clicked the label shows the values of the object-variables.
A class "CCAR" is defined, it has three variables, a constructor and three methods.
At starttime, an object of CCar is instantiated. The object-methods are used to get the object-variables.

## The Code:

### Fmain.class:

    PUBLIC car AS CCar

'this declares a variable of the type "CCar"

    STATIC PUBLIC SUB Main()
      DIM hForm AS Fmain
      hForm = NEW Fmain
      hForm.show
    END

    PUBLIC SUB _new()

'here, the variable car is instantiated
'an object of the type CCar is made
'you vcan use the constructor of the class
'or a setXYZ() method to set the values

      car = NEW CCar("mercedes", 400)
      car.setPrice(5064.67)
    END

    PUBLIC SUB Button1_Click()
      TextLabel1.Text=
        car.getBrand() & "<br>" &
        Str(car.getPS_Power()) & "<br>" &
        Str(car.getPrice())

'to use a method of car the following syntax has to be used:
'car.methodname()

    END

### CCar.class

## The Source

Download