+ 1
What's the difference between object's, class's and arrays
I'm still confused between difference of object's, class's and arrays
2 odpowiedzi
+ 4
Think of classes as blueprints and objects as the objects that one would create based upon the blueprint they have. Basically, the blueprint (class) is a template that maps out everything about the object you create with that blueprint. It'll let you know the properties of it, how it's made up, and what it's capable of doing once it is in the world. From there, you can create (instantiate) an object from that blueprint (class). Once you create an object in the world, you can use and manipulate that object as you see fit without impacting other instances of that object which may exist in the world. This allows you to use individual objects without affecting the other objects that were created from that blueprint. (Note: there are ways to enact change across all objects, but for the sake of this simple example, lets not focus on that. lol ) As well, this allows you to have a blueprint which can always be used to create new copies of the original object.
As for arrays, they're simply an 'array' of memory slots that is represented to us as a single memory slot. We do this to group up variables/items/data/etc... into a singularly named variable, as it makes it a lot easier to deal with than dealing with potentially hundreds of separate variables that are named something different. It's kind of like my pockets and my wallet. Each pocket is a single variable that I store something in, but my wallet is a container that contains a bunch of containers inside of it. My wallet is viewed as a single item, but when you open it up and look inside you see various pockets in it that each store individual items. It's easier for me to consider my wallet its own individual entity than giving a unique name to each and every pocket that contains data related to the other pockets in the wallet.
+ 1
Consider an animal as a class and type of animal like dog or cat can be considered as an object which has properties like size, color, strength, height etc.
Basically classes are for grouping the similar things or requirements which are related to functionality of that class.
These functionalities can be implemented using objects.
Array is similar to anyother datatypes like int but it is used to store more values of same type
Array of integers or array of strings..
Hope this is helpful