EXERCISE NO : 13(a) EXERCISE - 13(b)
Description:
Class variable: A variable that is shared by all instances of a class. Class variables are defined within a class but outside any of the class's methods. Class variables are not used as frequently as instance variables are.
Instance variable: A variable that is defined inside a method and belongs only to the current instance of a class.
self variable: The first argument to every method inside a class is a special variable self. Every time a class refers to one of its variables or methods, it must precede them by itself. The purpose ofself is to distinguish class‟s variables and methods from other variables and functions in theprogram.
For implementing Class Robot, a class variable called count, instance variable called nameand self variable self is used.To distinguish their usage, class variables are accessed using classname with dot(.) operator. Where as, instance variables are accessed using self with dot(.) operator.
For implementing Class ATM Machine, an instance variable called balance and self variable self is used to call the instance variable within the method of a class.
No comments