Ch.1 Unit.2
Ch.1 Unit.2
Learning Scope
" Introduction Real world obiects and software objects " Characteristics and
behaviour of real world objects and software objects "Class is an object factory
" Object is an instance of a class " Class is a user defined data type
Introduction
In real world, the class is a set or category of
things
sharing common_characteristics or qualities. Each Class
item belonging to a specific category possesses the Object,
characteristics and behaviour described within it.
If we consider furniture' as a category then different types of furnitures such as table,
chair, bench, etc. can be referred to as the items of category furniture. In software
terms, category and items are considered to be class and objects respectively.
Hence, class is a blue print/template/prototype that describes the characteristics and
behaviour for the similar types of objects. Objects are the entities which possess different
characteristics and common behaviour described within the class.
Let us consider an example of real world class to
understand the way different
characteristics and common behaviour are embedded in its objects.
La
Class TvSet SONY
Object 1
Object 2
Characteristics: Characteristics:
Size Size Characteristics:
Size
Number of channels Number of channels
Number of channels
Price Price
Price
Behaviour:
Common Behaviour:
Viewing TV programs
Playing games
Viewing TV programs
Viewing movies Playing games
Viewing movies
10 |Un
(renting an Object of a Class
object of a class can be
An created by using the following syntax:
<Cluss name> <Obiec name> =
new Class
With reference to the above illustration, some name>():
described under class named as TvSet'. The characteristics
objects of
and behaviour of TV
cRated shown -below: class TvSet' can be
T:Set SONY =new TSer(0:
T:Set LG = nes ISet):
The moment the objects are created, they will implicitly possess the
dhehaviour described within the class. Here, it is to be noted that characteristics
the objects SONY
ad LG will contain different characteristics (Size. Number of channels and
Price) but
they will possess common behaviour such as Viewing TV programs', Playing games
ond Vievwing movies". In this way, we can say that the class and objects are inter-related
to each other.
When class and objects are used in programming, they are known as software clasS
and objects. The description of class and declaration of the objects will take place in
the same way as the real world class and objects take (already discussed above).
Note:
A class declaration includes the following components:
Access Specifier: Aclass can have only access specifîer (i.e. public) whiçh is a default
specifier.
Class name: The class name must be meaningful with initial letter in uppercase.
Body: The set of statements comprising aclass must be enclosed under curly braces, { }.
used
Let us take an example to understand as how software class and objects will be
for programming purpose.
class Rectangle Objects
shown above, the class 'Rectangle' is designed with the data members
In the structure (input(), calculate() display(). The objects
and
(length ad breadth) and member functions
of the class can be created as shown below:
Rectangle Fig 1 = new Rectangle():
Rectangle Fig 2= new Rectangle():
Revision of Class IX Syllabus | 11
The structure shown above, stales when the objects Fig_l and Fig_2 are created then
cach object will automatically possess the data members and member functions described
within the class Rectangle'. The allocaion of data members pertaining to cach objct
can be different but the functions to be carried on them will be common.
Hence,
Fig_I.inpu() : will accept length and breadth of object Fig_I.
Fig_l.calculate() : will perform calculations by using length and breadth of object
Fig_I.
Fig_I.display() : will display the result of calculation of object Fig_I.
Similarly, you can show the above tasks for the object Fig _2.
With reference to creating objects of a class 'Rectangle', the complete program i
designed on BlueJ platform:
a program to calculate area of rectangle using class and function
import java.util.*:
class Rectangle
int l,b,ar;
public void Input()
ar=|*b:
Behaviour Functions
Viewing TV Programs input()
Playing Games calculate()
Viewing movies display()
Features of a Class
object factory: A class is used to create similar objects that possess
Class is an Hence, class is called an object
differentcharacteristics and common behaviour.
factory.
class: The data members declared within a class are also
Object is an instance of a of a class is created, it includes
instance
When an object
known as instance variables. This is the reason that object is called as
an
the class.
variable described within
instance of a class. becomes a data type
data type: When user creates a class, it
Class is a user defined
referred to as a user defined data type. This data type
is
Tor his program. Thus, class types such as int, float, char, etc. Hence, it is also said
includes different primitive
to be Composite Data Type.