Jump to content

Classes, Methods, and Objects

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
Sionofdarkness

Sionofdarkness

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 384 posts
What's the difference between these three things (classes, methods, and objects). Aren't they also in C++, I think that's one of the similarities between the two languages. Well, if someone could just tell me the relationship between them, that'd be great.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
A class is a definition of an object in an object-oriented programming language (including C++, Java, Delphi, C#, VB, and many others). For example: "A dog is a mammal in the canine family that has been domesticated" would be a class.

An object is an instance of the class. For example: Fido, Fluffy, Bruno, and Kujo are all objects of the dog class.

A method is a function that objects of a class can perform. For example: all dogs can bite(), bark(), walk(), run(), sit(), and roll_over().
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Sionofdarkness

Sionofdarkness

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 384 posts
Very interesting, that explained a lot. Can you also give me a real-code example, because I'm sure that's not how it works in the coding world (you know what I mean). Thanks again!

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
In Java, everything's a class. For example, a Window has location, width, height, and you can tell it to show(), hide(), resize(x,y), move(x,y), etc. Check out Thinking in Java for plenty of examples.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
Sionofdarkness

Sionofdarkness

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 384 posts
Oh, now I get it (at least, a little more).

#6
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Classes are usually used to model things. Things have properties, such as size, location, etc., and abilities, such as moving, storing, making noise. Properties are generally called something like attributes, and abilities are called methods, which work just like functions.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#7
Sionofdarkness

Sionofdarkness

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 384 posts
Each time you respond, I understand more and more.