Oops related Doubt

In interviews if someone asking: - without creating an object which type of method we can access option is :-

  1. Static Method
  2. Instance Method
  3. Class Method
  4. All of these
    the answer is Class Method but in static method we also access the method of class without creating an object even with help function we can see the method which we have declare while creating an method. so my question is which is the correct option and please also explain with an example :slight_smile:

Static method and class method both can be accessed without creating an object.

The difference relies on the capability to access other methods and class attributes but no instance attributes.


So first let us understand us
what is object ?
Object is presence of class .i.e. physical extension of class
we can create any number of object for a class

what is class ?
In simple words you can say class is a blueprint of your object .
class contains various functions and properties

Class method:
When we are using static variable inside any method then overall method will be a class method.
In class method, to define it we are using @classmethod decorator
We can access class method without creating any object

Static method:
Inside these method we cannot use any instance or class variable
In this method , to define it we use @staticmethod decorator

1 Like