Quote:
Paragraph 3 on page 104 says:
"A class defines the characteristics of any objects from that class. Your code can use the new keyword to create OBJECTS of the class."
Should that say: "Your code can use the new keyword to create INSTANCES of the class" ??
What is the difference between "objects of a class" and " instances of a class" ?
|
There really isn't a difference between "object" and "instance" in this case. The difference mostly one of which sounds better. You "instantiate" a class to make an object. The object you make is an object and it is an instance of the class.
Note, though, that "object" is a more generic term. An object of any class is an "object" so a car, person, or form is a type of object. It doesn't really make sense to say something is an "instance" without saying an instance of which class.
Quote:
|
What is the hierarchy of forms?
|
If you look up a class in the documentation, you can learn from what class that class is derived. If you go to
Form Class, you can see that its inheritance hierarchy is actually:
Code:
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.ScrollableControl
System.Windows.Forms.ContainerControl
System.Windows.Forms.Form
Quote:
|
There is a Form in System.Windows.Forms right? Is that a class or an object?
|
System.Windows.Forms is a namespace. It's sort of a bunch of code that defines classes, enumerations, structures, and other stuff that is grouped for naming convenience.
One of the classes it defines is Form. When you make a plain old form, you are making an instance of the Form class defined in System.Windows.Forms, or the class System.Windows.Forms.Form.
Quote:
|
When we open a new Windows Forms Application, we see "Form1.cs" which was generated from System.Windows.Forms, right?
|
When you create a new Windows Forms project, Visual Studio creates a class for you that inherits from System.Windows.Forms.Form. So your Form1 class is a new class in the big inheritance hierarchy I listed above.
Quote:
|
So "Form1.cs" is a Class.
|
Yes.
Quote:
|
If we add a second form, it is another Class.
|
If you use the Project menu's Add Form command, then yes you are creating another class that also inherits from System.Windows.Forms.Form.
At run time, the program can create more than one instance of the Form1 class. In that case, they would all be instances of the same Form1 class.
Quote:
|
But we have to make an "instance" of the second Class in the Project before we can use it?
|
Yes. By default, when you make a Windows Forms application, Visual Studio makes a program that creates an instance of the default Form1 class and displays it. If you want to make other instances of that class, or if you want to display instances of the Form2 class, then you need to make and display them in the code.
Quote:
|
So a Class is the template for an Object, or an instance of a Class is an Object?
|
Both. A class is a template for creating objects, which are called instances of that class.
Quote:
|
Form, Class, Instance ... where does Object come in?
|
If you think of instance is just another word for object, you've pretty much got it. The only real difference is that when you say "instance" you also have to say which class. It's more a semantic thing that a real difference between the two terms.
(I suppose you could say something is an instance without saying of which class it is an instance. But normally you would say "it's an instance of the Person class," for example.)
I hope that helps.