+ 1
Can anyone explain class method i totally confused in this topic please help.
Need explanation on class
2 Respuestas
+ 1
Class has features and methods.
The features are variables and the methods are functions that you add to the class.
If you create a class for OOP that's the base.
But if you use main method so it's the class which might use the objects and not create them or just do some other things of OOP.
0
Classes are blueprint of objects...
Instance is an object created based on the blueprint.
Class define properties (attributes) and methods (functions) related to the instances object or not directly related (but usualy logicaly related).
ie: we could create an Engine class, with properties such as type (heat, electric...)... and methods such as start, stop... (instance properties and method). We could also create class properties and methods (wich doesn't require an instance object to be used), such as count of Engine class instances created (class property) and/or a function to access this counter (class method) wich both applied to the family rather than a specific instance.
We create any instances of Engine:
heatEngine = Engine::construct(type='heat',...)
electricEngine = Engine::construct(type='electric',...)
... and we use them:
heatEngine::start()
heatEngine::stop()
... and we could use a class method (or property):
engines = Engine::count()
(pseudo-code because you didn't specify any language)