210k views
1 vote
When is is necessary to create an object to call a method?

A. When the method is an instance method.
B. When the method has a return value.
C. When the method is void.
D. When the method is a static method.

User YaBoyQuy
by
8.2k points

1 Answer

5 votes

Final answer:

You need to create an object to call a method if it is an instance method, as opposed to static methods which don't require an instance of the class to be invoked.

Step-by-step explanation:

It is necessary to create an object to call a method when the method is an instance method. An instance method belongs to an instance of a class, and thus requires an object of that class to be created in order to invoke it. In contrast, static methods can be called without creating an object because they belong to the class itself, not any particular instance.

The presence of a return value or the method being void is irrelevant to the need for an object; this requirement is solely based on whether the method is static or an instance method.

User Fergmux
by
7.8k points