Objects can be considered as analogous to real-world objects
Technically, an object is an instance of a class or structure
Consider a Mobile Phone as an example
To sum it up, phones such as Google Pixel, Samsung Galaxy, iPhone 10 etc are objects
of Mobile Phone,
where a Mobile Phone is a class or structure which classifies the properties and functionalities of its objects
So the class Mobile Phone can inform that any of its objects (i.e. any specific mobile phone) can have (and in some cases, should have) properties such as brand name, model, 4g support, wifi, Ram, processor etc
And the objects(such as Google Pixel, Samsung Galaxy, iPhone 10 etc) fill the values for these properties, (such as brand name:"google", model:"Pixel 2", 4g support:True, Ram:6gb etc )
Some properties can be pre-filled by a class, such as type: "Electronic device", chargeable: "True"
Above example of Mobile Phone and a specific model of a brand as class and its object, can instead be related to a concept of programming called inheritance
To get an idea of how a class defines functionalities for its objects, assume that a specific mobile phone such as Google Pixel is a class
With that assumption, a Google Pixel belonging to Mr X is an object, and one belonging to Mr Y is another object
Now class Google Pixel has some pre-filled properties like Ram:6gb, processor name:Snapdragon, screen size etc
This class can define functions such as battery_percentage(), available_storage(), internet_connectivity() etc
These functions are callable, as in, they can respond based on demand or an event
Such event can be due to the user (termed as explicit), such as button click
Or it can be automatic (implicit), based on another event(such as incoming notification or phone call) or a periodic
So when Mr X opens his phone (which is also a function open()
), it can call many other functions implicitly,
one of them being battery_percentage()
which returns the percentage of current available battery backup and is
probably different than that returned in Mr Y's phone, and the system then displays this value in the top notification bar
and/or fills up the battery icon based on it (if configured)
Some functions can be overridden by an object
For example,