+ 7
what is difference between objects and classes?
3 Réponses
+ 4
A class defines what the properties of an object are and what it can do. A class "Person" would include properties like Name, Gender etc. and Methods like Speak(...); a class (A struct would be better in this case. You'll learn about them.) "Rectangle" would have the properties A and B and Methods like Fill(...).
To use them you need objects. You cannot execute Person.Name = "Sue";. However if you have an object Foo of the class Person (an instance), Foo.Name = "Sue"; will work.
There is also a way how classes (or some of their part) can become kinda like an object. This is done by using "static". A static property is shared between all instaces of a class (only one copy of it exists, don't worry abput heavy memory use). If the whole class is static you don't even have to instantiate it. Assuming Person is now static, Person.Name = "John"; would work.
+ 3
Class is the structure, the blueprints, and the objects are the creation, the building.
+ 2
Classes are blueprints for Objects.