Attributes and Methods

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

Introduction

Attributes (data members) store state; methods (member functions) define behavior of an object.

Definition

Attributes: data members. Methods: member functions.

C++ Code Example

class Car {
    string color; int speed; // attributes
public:
    void accelerate(){ speed+=10; } // method
    void show(){ cout<

Important Questions

Short Questions

  1. Define attribute.
  2. Define method.
  3. Difference attribute vs method?
  4. What is data member?

Long Questions

  1. Explain attributes and methods with example.
  2. Discuss role of methods.

MCQ Practice

1. Attributes are:

  • Data members
  • Member functions
  • Classes
  • Objects
Answer: Data members.

2. Methods are:

  • Member functions
  • Data members
  • Variables
  • Macros
Answer: Member functions.

3. Attributes store:

  • State
  • Behavior
  • Code
  • Nothing
Answer: State.

4. Methods define:

  • Behavior
  • State
  • Memory
  • Type
Answer: Behavior.

5. Member function declared inside class is:

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

Quick Revision

  • Attributes = state; Methods = behavior.