Hey guys I have a question.
I didn't quite understand why do I have to write the keyword new and the () in SpecialThread
- - >> new Thread (new SpecialThread ());
Wouldn't be enough just address SpecialThread and nothing else? Or is it because it is a static class?
I don't understand why?
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
5 January 2021, 14:44
SpecialThread is not an object, it is a class. Classes are blueprints for objects that tell the computer what the object is, what it contains, and what it can do. You can't use a class (there are exceptions to this, though that is a more complex discussion) until you make a valid object out of it. You make a class an object by calling the new keyword along with (one of the) the class constructor. Not doing so would be the same as creating a variable without initializing it, then trying too use it. For example, this makes no sense:
This code would not work because a has not been initialized and the value of it does not exist. 0