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.
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().
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!
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.
Oh, now I get it (at least, a little more).
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.
Each time you respond, I understand more and more.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks