You are on page 1of 1

OOP

Class
Class acts as a template for an object

Class constructor
The new keyword creates a new instance of the class you specify.
o CupOfCoffee myCup = new CupOfCoffee();

o CupOfCoffee myCup = new CupOfCoffee("Blue Mountain");

Calls code within the .NET Runtime that creates new instance if the type, and hands you back a
reference

Code inside the class that runs as class is created is called the constructor

Class can contain multiple constructors

o Overloading makes this possible


Every class needs a constructor

o .NET Runtime executes code within the class that causes the object to load into memory

Compiler will automatically create an empty constructor


You can create your own constructor and pass arguments
Classes can have multiple constructors (This is known as overloading)
Basic initialization of an object is automatic.
All class definitions contain at least one constructor.
These constructors may include a default constructor, which is a parameterless method with
the same name as the class itself.
A class definition might also include several constructor methods with parameters, known as
nondefault constructors.
Constructors, like fields, properties, and methods, may be public or private.
Code external to a class cant instantiate an object using a private constructor; it must use a
public constructor.
Constructors (or any other method), as you know, are invoked at runtime.

You might also like