Whether you do it in two steps or one is largely a matter of preference for how your code is organized. You can certainly do both in the same line to save space in the program, for example:
Code: Select all
Phidgets.Encoder encoder = new Phidgets.Encoder();
But the reason it requires the 'new' keyword when a primitive data type like an int or char does not, is because objects are like customized data types. The compiler already knows what an int is, but it doesn't know what a Phidgets.Encoder is. The 'new' keyword tells it to start up the class constructor, which defines all other variables and functions contained in the class.
Additionally, since objects can take up a variable amount of space, memory needs to be allocated when a new object is created, and recouped when the object is destroyed.