Alex Rivera | Logout

Do I correctly understand what a class is?

Asked 2010-03-21T00:44:20.333
14

I've had trouble finding a clear, concise laymans definition of a class. Usually, they give general ideas without specifically spelling it out, and I'm wondering if I'm understanding this correctly. As I understand it, a class is the set of code that controls an object. For example, in an app that has a button for 'Yes' and a button for 'No', and a text box for output, the code that tells the computer what to do when the user uses the Yes button is one class, the code for hitting No is another class, and an object is the two buttons and what they do together to influence the output box. Am I right, or am I confusing terms here?

Thanks

Edit
Report

1 Answer

2

This is going to be a very simplified explanation. A class is a set of functions and variables and is used to create objects. I think it's good to use real examples instead of dog / bark / talk etc.

  • Class Email
    • Subject (string)
    • Message (string)
    • ToAddress (string)
    • FromAddress (string)
    • Send (function)

When you call 'new Email()' it creates a new object with those variables and functions. Then you can populate the variables and send it.

answered 2010-03-21T01:02:29.833

Your Answer