0% found this document useful (0 votes)
84 views

Chapter 2 Question answers

Chapter 2 discusses the fundamental concepts of objects and classes in object-oriented programming. It defines objects as entities with attributes, behaviors, and state, and explains the role of classes as blueprints for creating objects. The chapter also covers topics such as encapsulation, abstraction, and how objects communicate with each other through method calls.

Uploaded by

pandeyjeeom60421
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views

Chapter 2 Question answers

Chapter 2 discusses the fundamental concepts of objects and classes in object-oriented programming. It defines objects as entities with attributes, behaviors, and state, and explains the role of classes as blueprints for creating objects. The chapter also covers topics such as encapsulation, abstraction, and how objects communicate with each other through method calls.

Uploaded by

pandeyjeeom60421
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Chapter 2

Answers
1. What are objects? Give five examples.
Answer: Objects are identifiable entities with attributes, behavior, and state. They are the basic
units of an object-oriented system.
Examples:
• Mobile
• Car
• Chair
• Bank Account
• Person

2. Explain the anatomy of an object.


Answer: An object's anatomy consists of:
• Attributes: Characteristics that define the object (e.g., color, model).
• Behavior: Actions the object can perform (e.g., dial, start).
• State: The current values of its attributes (e.g., color: red, status: off).

3. Explain the following statement - "Class is a specification for objects".


Answer: A class is a blueprint that defines the attributes and behaviors of objects. It specifies
how objects of that class should be created and what they can do, but it is not the object itself.
For example, the Mobile class specifies attributes like model and behaviors like dialing, which
objects like iPhoneX follow.

4. Explain the following statement - "Abstraction is relative to the perspective of the


viewer".
Answer: Abstraction depends on the viewer's needs. Different perspectives highlight different
attributes of the same entity. For example, a car driver sees a car’s model and comfort, while a
mechanic focuses on its engine and brakes, choosing the abstraction relevant to their purpose.

5. Identify five possible attributes and three possible behaviours of the following entities:
Answer:
a. School
• Attributes: Name, address, number of classrooms, principal, established year.
• Behaviors: Conduct classes, organize events, issue certificates.
b. Student
• Attributes: Name, roll number, grade, date of birth, address.
• Behaviors: Study, attend classes, submit assignments.
c. Teacher
• Attributes: Name, subject, employee ID, qualification, experience.
• Behaviors: Teach, evaluate assignments, conduct tests.
d. Computer
• Attributes: Brand, processor, RAM, storage, operating system.
• Behaviors: Run programs, connect to the internet, save files.
e. Television
• Attributes: Brand, screen size, resolution, model, channel list.
• Behaviors: Change channels, adjust volume, display content.
f. Washing Machine
• Attributes: Brand, capacity, model, water level, wash modes.
• Behaviors: Wash clothes, spin, dry clothes.
g. Chair
• Attributes: Material, color, height, weight, design.
• Behaviors: Support weight, adjust height (if adjustable), fold (if foldable).
h. Person
• Attributes: Name, age, address, eye color, Aadhaar number.
• Behaviors: Walk, talk, drive.

6. Explain in detail how a class is different from an object.


Answer:
• A class is a blueprint or template that defines attributes (member variables) and behaviors
(methods) but doesn’t hold specific values or occupy memory. It’s a logical entity.
• An object is a concrete instance of a class with specific attribute values and allocated
memory. It’s a physical entity that behaves as per the class’s methods.
• Example: The Mobile class defines attributes like model and methods like dial. An
object, iPhoneX, has specific values (model: iPhone X) and performs actions like dialing.

7. Give the reason why a class is known as:


a. An object factory
Answer: A class acts like a factory because it can create multiple objects (instances) with the
same attributes and behaviors, like a Mobile class producing many mobile objects.
b. A composite data type
Answer: A class combines multiple data types (attributes) and methods into a single unit,
allowing complex data structures, unlike simple types like int.
c. A user-defined data type
Answer: A class is defined by the programmer to represent custom entities (e.g., Account), with
its own attributes and methods, unlike built-in types like float.

8. How are classes and objects inter-related? Support your answer with an example.
Answer: A class defines the structure (attributes and behaviors) for objects, and objects are
instances created from that class. They are inter-related as a class is the template, and objects are
its realizations.
Example: The Account class defines attributes like balance and methods like deposit. Objects
myAccount and yourAccount are created from this class, each with specific balances but sharing
the same structure.

9. What do you understand by the term objects encapsulate state and behaviour?
Answer: Encapsulation means an object stores its state (attribute values) in member variables
and exposes its behavior through methods. Only these methods can access or modify the state,
hiding internal details. For example, a Mobile object’s state (model: Samsung) is changed only
by its methods like dial, keeping data secure.

10. Explain how objects communicate with each other.


Answer: Objects communicate by sending messages, where one object (sender) requests another
object (receiver) to perform an action using its methods. For example, a Person object (Mohit)
sends a message to an Account object (myAccount) by calling myAccount.Deposit(1050),
instructing it to add money to the balance.

You might also like