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

Assignment 2

This document contains sample questions and answers related to object-oriented programming concepts like classes, objects, methods, encapsulation, etc. Some key points covered are: 1. The definitions of attributes, behaviors, and methods as they relate to classes and objects. 2. The differences between a class and an object - a class is a blueprint that defines attributes and behaviors, while an object is an instance of a class with a physical existence in memory. 3. How objects encapsulate state and behavior through attributes and methods defined in their class. This provides abstraction and data hiding.

Uploaded by

Sneha Bhatia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

Assignment 2

This document contains sample questions and answers related to object-oriented programming concepts like classes, objects, methods, encapsulation, etc. Some key points covered are: 1. The definitions of attributes, behaviors, and methods as they relate to classes and objects. 2. The differences between a class and an object - a class is a blueprint that defines attributes and behaviors, while an object is an instance of a class with a physical existence in memory. 3. How objects encapsulate state and behavior through attributes and methods defined in their class. This provides abstraction and data hiding.

Uploaded by

Sneha Bhatia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

SOLVED QUESTIONS

Sectlon-A
(Short Anwer '1ypu (yientlona
1.) Defne: (a) Attribute (h) Behavlonr (e) Method.
Ans. Attribute. An attribute is n lutn value held by the objeels in n clans, It can be the strueture, nume,
size and other characteristies of an object. tg, nme, uge, belght anl weight ure the ttilutes ot
he objects of the class person,
Behaviour. lt is an action that an objeet performs.
Method. A specitic implementation of an operution by a certain cluss is called nnetlwd.

2. What does nn objeet transfer to the other?


Ans. An object transfers messuge to aanother olbject.

3. Differentinte betveen a euss und an ohjecet.


Class Ohject
is instunee ol n class.
Ans. Class is a blueprint or template from wlhiclh Objeet an

objects are created.


hns plhysical existencc.
Class has logical existence. Object
For class, memory space is nol allocated, wlhen I n case ofan object memory spuce is allkcnteu,
when it is ereated.
it is created.
. Class is declared once. Object is ereuted many times.

Class is declared using the keyword 'class. .Object is creuted througlhthe keyword "new.
behavlour?
4. How object model an entity and its
can an

Ans. Modelling: Modeling refers to developing or givinga


shape.
that has a body.
Entity: An entity refers to anything an entily perlorms is called an operation.
Behaviour/Operations: An action that
used to describe the dala structure and its behaviour in a single entity.
Object: It is a term

is class called an object factory?


5. Why a
infinite set of individual objects. So, it can be culled as a factory
Ans. Each class describes possibly an
class of cellphone can have numerous objects as Nokia, Sumsung,
of objects. For example, a
of the objecls are deseribed within the class.
Panasonic, etc. The features and funclions
the attributes and nethods of the object. Comment.
6. Encapsulation wraps up
the
Ans. Encapsulation wraps up the atlributes and methods of an object into a single unit. It makes
them snfc from being misusel.
classes independent and keeps
7. How does an object maintaln its ldentity?
It meuns that two objects are distinet even if they have same
Ans. An object has its own identily.
two Muruti's ure plhysicully distinet though they are thec
attributes (structure, name and size). e.8,
Ssame objects, i.e., Maruti.
to show that objects encnpsulate stnte nnd behuvlour.
Write two examples
As Every object has its own altributes Samsung like a cellphone hus its charncteristies of memory
maximum and minimum tone, volume, its size and shape. It also has
(size), number of ring tones,
like send und reccive calls, games, etc. Thus, its stnte (nttributes)
its own behaviour(functions)
one unit thut is "Object".
the behaviour is bound in
and
Elementary Concept of Ohjects annd Classes
9. What does a class need to define, when used as a data type in a Java project?
Ans. A class needs to defiue data variables to store the data valuces and functions or methods that
define the process to be performed on the objects of the class. These data variables are called
member variables and the methods are called member functions or member methods.
10. How does n class implement data nbstraction and encapsulation features of 00P?
Ans. A class defines the data variables (cnlled member variablcs) and the methods/functions (called
member functions) common to a set of objects of the class. In other words we can say that these
members variables and functions are encapsulated into a single unit called class. This encapsulation
leads to abstraction (hiding). Due to this encapsulation, users know how to access the encapsulated
code no matter what the details
implementation are.
11. Is it possible that an object has more than one abstractions? Explain with examples.
Ans. Yes, it is possible for an object to have more than one abstraction. This can be understood from an
example of an employee. The attributes and methods for the personal details of an employee can
be wrapped up in a class named "Personal" and the attributes and methods related to details of
the employees salary can be wrapped up in another class named "PaySlip". Thus, the same object
can possess multiple abstractions by encapsulating relative attributes and methods in more than
one classes. Similarly, an account holder can have the personal details in one class say-AccHolder
and the details of the account in another class
say-AccBalance.
12. How to create an object in Java?
Ans. An object is created from a class. In Java, the new key word is used to create new object.
For example: progl objl =
new prog1()
Where progl is the class, objl is the newly created object's name and prog1) is the con_tructor
of the class.
(13 What declarations are required for every Java application?
Ans. A class and the main() method declarations.

Why an object is called an instance of a class? [2010]


Ans. A class encapsulates
the data members and member functions. It is used to
create an
object. A
class is an object factory. Hence, an object is called an instance of a class.
S.) Why is a class known as composite data type?
Ans Class is called a composite data type because it binds up
types together as a single data type.
(encapsulates) one or more
primitive
e.g, class Abc {
int
float y

16. What does the following mean?


Employee stalf=new Employee);
Ans. The statement
Employee staff new Employee( ) creates
=
an object named staff of the class
Employee. also allocates memory to the object.
It
17. How is a class type variable declared?
Ans. Declaration or creation of
class type variable
8. What is this
(object).
Ans. The class
elass type variable called?
type variable is called object of the class.
30 7ogcther wieh
Computer Applications (ICSE)-9
Scanned by CamScanner

You might also like