In object-oriented programming, non-static methods are methods that belong to an instance of a class, not to the class itself. When you call a non-static method, an object must be created for the class to call the method.
Here are some reasons why we create an object for a non-static method:
1) Encapsulation: non-static methods are typically used to encapsulate behavior specific to an instance of a class. By creating an object for the class, we can access the non-static methods and properties of that particular instance and encapsulate its behavior.
2) Object-oriented programming principles: creating an object for a non-static method follows the principles of object-oriented programming, where objects represent instances of a class and contain state and behavior. By creating an object, we can access the behavior of that particular instance and change its state.
3) Code reusability: Non-static methods can be used across multiple instances of a class, which enables code reusability. By creating an object, we can call the same non-static method in multiple instances of the class and reuse the code.
4) Polymorphism: Non-static methods can be overridden in subclasses, enabling polymorphism. By creating an object, we can call the non-static method in a subclass and override its behavior.
In summary, we create an object for a non-static method to encapsulate the behavior of an instance of a class, follow the principles of object-oriented programming, reuse code, and enable polymorphism.