Create An Object From A Class
Now, that you have a class, it is easy to create an instance of the class by using the keyword “new.”
EXAMPLE:
MyBox box1 = new MyBox();
NOTES:
- When creating an object from a class, you always have to do these three processes:
- Declaration—declare the type of object you want to create based on the class name (e.g., MyBox) and its variable name (e.g., box1)
- Instantiation—use the keyword new to instantiate an object and call its constructor method (e.g., new MyBox()).
- Initialization—if necessary, give the object initial values (e.g., new MyBox(30,30)).
- The Java class syntax is identical in C# and similar in other OOP languages like VB.NET, Ruby, etc.