what is difference between objects and classes? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 7

what is difference between objects and classes?

6th Jan 2017, 7:32 PM
Norayr Hambardzumyan
Norayr Hambardzumyan - avatar
3 Answers
+ 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.
6th Jan 2017, 8:55 PM
Maike
+ 3
Class is the structure, the blueprints, and the objects are the creation, the building.
6th Jan 2017, 7:38 PM
Nahuel
Nahuel - avatar
+ 2
Classes are blueprints for Objects.
6th Jan 2017, 7:39 PM
Jonas Fallmann
Jonas Fallmann - avatar