State, Identity, Behavior

Unit 2 Β· Topic 2.7⏱ 8 min read❓ 5 MCQs

Introduction

State = attribute values; Identity = unique existence; Behavior = methods an object performs.

Definition

State: data values. Identity: unique object. Behavior: methods.

C++ Code Example

class Light {
    bool on; // state
public:
    void toggle(){ on=!on; } // behavior
};
// identity: each Light object is distinct

Important Questions

Short Questions

  1. Define state.
  2. Define identity.
  3. Define behavior.
  4. Example of each?

Long Questions

  1. Explain state, identity, behavior with example.
  2. Discuss their importance.

MCQ Practice

1. State refers to:

  • Attribute values
  • Methods
  • Class name
  • Memory address only
Answer: Attribute values.

2. Identity refers to:

  • Unique object existence
  • Values
  • Behavior
  • Type
Answer: Unique object existence.

3. Behavior refers to:

  • Methods/actions
  • Data
  • Class
  • Memory
Answer: Methods/actions.

4. Which changes over time?

  • State
  • Identity
  • Behavior
  • None
Answer: State.

5. Identity is unique per:

  • Object
  • Class
  • Method
  • Attribute
Answer: Object.

Quick Revision

  • State changes; identity unique; behavior = methods.