Q. The behaviour of the instances present of a class inside a method is defined by
โ
Correct Answer: (B)
Classes
Explanation:
Sure! Letโs break it down:
When you create instances (objects) of a class, the class defines the structure and behavior of those instances. Hereโs why:
Classes define:
- Properties (fields): Data that an instance holds.
- Methods: Functions that define what the object can do (its behavior).
Methods inside a class:
- When an instance of a class is created, any method you call on that instance behaves according to how the method is written in the class.
- For example:
Interfaces:
- In languages like Java, interfaces define a contract that a class must follow, i.e., the methods a class must have. However, interfaces donโt define how those methods work โ that's the job of the class.
- For example:
In conclusion:
- Classes define the behavior of instances of the class, as they contain the actual methods that define what those instances do.
- Interfaces only define what methods the class must have, but not the implementation (behavior) of those methods.
Therefore, the behavior of instances inside a method is defined by the class.