Page 129 - ComputerScience_Class_11
P. 129
C. Answer the following questions:
1. What are the components of objects?
Ans. The components of objects are state, behaviours and events.
2. What are the components of classes?
Ans. The components of classes are the access specifier, class keyword, class name, data members and methods.
3. What is a user-defined data type? Give an example of it.
Ans. A user-defined data type is a derived data type depending on some existing data types. Class is an example of a user-defined
data type.
4. Define object.
Ans. An object is a unique entity that contains properties, methods and events together in an object-oriented programming language.
5. Define class.
Ans. A class in Java is a non-primitive/user-defined data type that acts as a blueprint for creating objects of the same type.
6. Why class is known as an object factory?
Ans. Factories are places which produce products of the same kind. A class acts as a factory as by using it, similar types of objects are
created with different characteristics and common behaviours. We can also say that a class is a blueprint of objects. Hence, a class
is called the object factory.
7. Why an object is known as an instance of a class?
Ans. As soon as an object is created in Java, it acquires memory in RAM but this does not happen while defining a class. Thus, objects
are the physical existence of the class. We know that data types such as int, long, float, etc. are predefined classes in Java, similarly,
user-defined classes create objects that contain all the properties and methods of those classes and also acquire memory.
Thus, we can say an object is an instance of a class.
8. What do you mean by exception handling?
Ans. When an exception occurs, the program stops immediately with a system-generated message. To provide a user-friendly message,
we need to handle the raised exceptions. Using it, we can ensure that the flow of the program doesn’t break when an exception
occurs. So, exception handling is a mechanism to handle errors occurred during the execution of the program so that the normal
flow of the code can be maintained.
D Higher Order Thinking Skills (HOTS)
1. In a school management system, you are designing a system that stores student information such as name, roll number and
grades. How would you design the class to store this information and perform tasks such as calculating average grades and
displaying student details?
Ans. Create a Student class with data members like name, roll number and grades (e.g., int[] grades). Include methods like
calculateAverage() to compute the average grade and displayDetails() to show the student's name, roll number
and grades. The class acts as a blueprint for student objects.
2. In a game development scenario, you need to represent different characters with varying attributes (e.g., health, strength and
speed). How would you use Java classes to model this?
Ans. Create a Character class with data members such as health, strength and speed. Define methods like attack() to perform
actions and defend() to reduce health. Use this class to create objects representing different characters in the game, each with
unique values for their attributes.
E. Assertion and reasoning questions.
The following questions consist of two statements – Assertion (A) and Reason (R). Answer these questions by selecting the
appropriate option given below:
a. Both A and R are true and R is the correct explanation of A.
b. Both A and R are true but R is not the correct explanation of A.
c. A is true but R is false.
d. A is false but R is true.
Objects 127

