Wrox Programmer Forums
|
BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer
This is the forum to discuss the Wrox book Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer by Rod Stephens; ISBN: 9780470596906
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 9th, 2013, 03:18 PM
Authorized User
 
Join Date: May 2013
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default Page 104 - Classes and Instances

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" ?

What is the hierarchy of forms?

There is a Form in System.Windows.Forms right? Is that a class or an object?

When we open a new Windows Forms Application, we see "Form1.cs" which was generated from System.Windows.Forms, right?

So "Form1.cs" is a Class.

If we add a second form, it is another Class.

But we have to make an "instance" of the second Class in the Project before we can use it?

So a Class is the template for an Object, or an instance of a Class is an Object?

Form, Class, Instance ... where does Object come in?

Last edited by John S; July 9th, 2013 at 03:30 PM..
 
Old July 26th, 2013, 11:13 PM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

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.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Page 104 kinvig BOOK: Professional ASP.NET MVC 2 0 September 13th, 2010 12:12 PM
Page 104 Nicholsen BOOK: Professional ASP.NET 2.0 Server Control and Component Development ISBN: 978-0-471-79350-2 0 November 27th, 2008 05:37 AM
confuse page 104 kencheung BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 August 16th, 2004 03:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.