Instances are nothing but the classes that hold the data and can perform the behaviours.
Following is a code of a class.
Above code is a Class named "Routers" and working_layer is a Class Attribute.
"brand" and "OS" are Instance Attributes.
"description" is a Method, specifically an Instance Method which is the most common method we see.
Following is an example of creating an object.
Since there are 2 Instance attributes defined within the class, we have to pass values for those 2 attributes like arguments.
Here an object named "R1" is created based on the class "Routers" and brand and OS is mentioned when creating the object. Later they were retrieved using <object name>dot operator<attribute>.
Since the "working_layer" is a class attribute, both R1 and R2 shares the same info while the other info is different.
If we call the Method, the out put will be like the following,
No comments:
Post a Comment