- 2071 Magh · 2+3 marks
Define object; method implements behavior
Short answer
An object is an entity with identity, state (attributes), and behavior (operations). Behavior defines what an object can do; a method is the actual code implementing that operation, changing state or returning values. Without a method, an operation remains a declaration; a method thus justifies behavior by providing the concrete implementation.
Define Object with example. A method implements the behavior of object. Justify.
Object
An object is an entity of the problem domain that has identity, state and behaviour. It is an instance of a class. A student, a bank account, a book or a car are objects.
Example: Object acc1 of class Account
- Identity:
acc1(distinct fromacc2) - State (attributes):
accNo = 1001,balance = 5000 - Behaviour (operations):
deposit(),withdraw(),getBalance()
+-----------------------+
| acc1 : Account |
|-----------------------|
| accNo = 1001 | state
| balance = 5000 |
|-----------------------|
| deposit(), withdraw() | behaviour
+-----------------------+
A method implements the behaviour of an object
Behaviour is how an object acts and reacts, in terms of state change and message passing. It is the what an object can do, decided in analysis as an operation (e.g. "an account can be withdrawn from"). A method is the actual code that carries out that operation inside the class.
Justification:
- Every behaviour (operation) of an object needs a concrete body that changes the state or returns a value; that body is the method.
- When another object sends a message
acc1.withdraw(500), it is the methodwithdrawthat runs, checksbalance >= 500and reducesbalance. This is the observable behaviour. - Without the method, an operation is only a declaration with no effect.
- Different classes may implement the same operation by different methods (polymorphism), which gives different behaviour for the same message.
So behaviour is the abstract responsibility and the method is its implementation.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Behavior modeling and four diagrams · Object Oriented Analysis and Design, chapter 2
- Requirement elicitation and system behavior · Object Oriented Analysis and Design, chapter 2
- Representing dynamic behavior in OOA · Object Oriented Analysis and Design, chapter 2
All Object Oriented Analysis and Design chapter 1 questions →