







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








of real world objects and software objects, Class as a specification of objects, creating objects
as a user defined function, declaring states and methods of a class, object as an instance of a (^) class, (^) differences between class (^) and (^) object.
and (^) Inheritance. An (^) Object (^) Oriented (^) Programming (OOP) (^) language not (^) only promotes these features but also correlates two more basic units (i.e. Objects and Classes). In this chapter, we are going to discuss the features or properties of objects and classes applicable to real world as well as to software world.
OBJECTS An (^) object is afundamental unit of (^) Object (^) Oriented (^) Programming and
the real life (^) entities. In (^) Object (^) Oriented (^) Programming (OOP), the (^) attempts are
with each other.
(a) Real World Objects (b) Software Objects
REAL WORLD OBJECTS
following features: " (^) It (^) is (^) visible to us.
28
Tiger
The characteristics are: Model
" App
The behaviours are:
"
Each real world object contains characteristics and behaviours. The characteristics basically comprises the parts of its body or specifications whereas, behaviour is the purpose of its use or its functions.
" It is used to talk.
For example,^ A^ mobile^ phone^ (cell^ phone)^ can^ be^ defined^ as^ a^ real^ world object that possesses some characteristics and behaviours as explained below.
Cycle (Real World Objects)
" It is used to browse the Internet. It is also used for net banking.
Table
Similarly, you^ can^ consider the^ Table'^ as^ an^ object.
Car
The characteristics of a table are:
" It has four legs.
The behaviours^ of^ a^ table^ are:
" It is^ made^ up^ of^ wood.
" It^ is^ used^ to^ keep^ copies^ and^ books.
9
8
Mobilephone
YOU CANY OO IT E
Clock
the living^ things^ are^ also considered^ as^ real world
whose characteristics^ may be^ defined^ as^ their features and
their behaviour^ may be defined as the role or function they perform.
Elementary Concept^ of^ Objects^ and^
Classes 29
Real World (Book)
(Student)
Chapters
States or Characteristics
Pages
Name
Marks
State or Characteristics
MESSAGE PASSING
Real Worid Object (Book)
Behaviour
Data Members
prepare notes
Real World Object (Book)
Function
A comparative study of behaviours and functions:
Data
Object A
Used to read Used to prepare notes
Message Passing
Accept( ) Display( )
Data Members
Behaviour
Software Object (Student)
Functions
It is interesting to know that the objects can interact with each other. An object can pass information to another object and receive information as well. They interact through behaviour or functions, which are better known as Message
Functions
Software Object (Student)
Function
Data
Object B
Elementary Concept^ of^ Objects^ and^ Classes^
31
Class
and behaviour. You might be thinking that from where these characteristics and
category that describes some characteristics and behaviour. Each object of a clas
in an Object Oriented Programming System. They can be considered to be the
and behaviour:
Characteristics colour
32
taste
shape
Apple (object 1)
used for making juice
Creating objects of a class
Common behaviour
used for festive occassions
Different types of fruits viz. apple, banana, pear, grapes are referred to as
objects which belong to the class "Fruits'.
used for breakfast
(object 2)
Fruits (class)
(Different types of fruits) Banana Pear (object 3)
common behaviour (shown in the table above).
Grapes
Understanding (^) Computer (^) Applications with (^) Blue<--IX
(object 4)
instantiation. All the (^) instances share the (^) state (^) (attribute) and (^) the
As the objects of class Car have been created, they will follow the structure as shown below:
34
Different Characteristics
Common Behaviour
class Flower
Characteristics: Colour Smell Behaviours:
Honda
Decoration
Colour
If you want to go for a journey on a Honda then the characteristics of Honda will be used. Similarly, it can also be understood for the
Worship
Model
colour and (^) mnodel but (^) will have (^) common behaviour like Journey and Demo.
statements:
Nano
" Let (^) us take (^) another (^) example. (^) Here, we (^) are (^) going to (^) assume (^) Flower' as (^) a class. The blue print or template of the class Flower' can be designed as shown below:
Rose
Colour
(object 1)
Model
Journey Demo
Understanding Computer Applications with Bluel-IX
Flower class
Aclass is simply a representation of similar types i of Objects. It is the blueprint/ i plan/ template that describes I the details of an Object.
Lily (object 2)
Maruti
Colour
Flower lily =^ new (^) Flower();
Model
Flower lotus = (^) new (^) Flower();
created by (^) using the (^) following
Lotus (object 3)
on the table shown below:
Colour
Rose Red Smell Yes
Different Characteristics
Colour
Lily
Just to Know
Yellow Colour Smell Yes Common Behaviour Decoration Garland Worship
different characteristics but they have common behaviour. The behaviour mainly refers to the functions to be carried out, on different objects. To carry the functions on different objects, the statements can be written as:
Lotus
rose. Decoration:It means the characteristics (Colour, Smell) of rose will be used for decoration.
Pink
used for decoration.
Smell No
used for worship.
Atypical Java class creates many objects and interacts by invoking methods. An object consists of:
Now, we will^ take^ examples^ of^ software^ class and objects that are used for programming
purpose in Java language.
the following^ data^ and^ member^ methods:
class Employee
//Data Members Name
//Member Methods AceptData( )
Elementary Concept of Objects and Classes 35
methods as shown below:
Rate Amount
and so on...
Note
TV set
Data members
4
public void Season()
50, 2,00,
Quantity
public void Season()
Rate Amount Member Methods
Calculate( ) Display( ) The member methods will be invoked on each object as: tvset.InputVal( ) :It will accept the Quantity and Rate of the tvset.
tvset.Calculate( ) :It will calculate the amount for the tvset. tvset.Display( ) It will display the amount for the tvset.
Cooler 5 8,
Since, youare not aware of the data types and writing Java statements, in the above examples of software class and objects, neither data types are mentioned nor the methods are defined. The templates and explanations are only for understanding the inter-relationship of class with its objects.
40,
relationship. Now, we are going to write an executable program by using different classes and their objects. As you are not aware of data types, variables
defined only with member functions.
class Mango
Elementary Concept of Objects and Classes 37
System.out.println("Applesare producedin Kashmir"); System.out.printin("Theyare availableduring Winter season");
publicvoidSeason()
System.out.println("Grapesare producedin Maharashtra"): System.out.println("Theyare availableduring Winter season");
MangoFruitl= new Mango();
SampleFuits ClassEdit Tools Options CompileUndoCut Copy Paste SourceCode 1/à sample programto create differentobjectsthroughmethods classMango { publicvoid Season() System. out.println("Mangois the kingof fruits"): System. out.println("Itis availableduringSummer season"):
classApple { publicvoid Season() System.out.println("Theyare availableduringWinter season");
System. out.println("Applesare producedin Kashmir")
classGrape publicvoid Season()
saved
System.out .printIn("Grapesare producedin Maharashtra"); Class compiled-nosyntaxerrors
(^38) Unders Compu Applicwith Blue<
Find..Close
and methodsas integrated components.
int, float,char,etc. Thesedata types providesome preliminary
programming.Whentheyare usedto declareany variable,
would possessits built-in characteristics.Hence,these types
characteristicsand behaviourwithinit. Thiscanbe doneby usinga class.
in data types. Similarly,
theclass.
Someof the attributesof the objectsof a classare explainedbelow:
ClassTelevision ClassStudent
(Functions)
State (Characteristics)
Methods
State (Characteristics)
Price Aadhar_No.
some characteristicsand behaviour.
operator.
2.It is an object producerand 2. It is createdwiththe helpof the 'new
(^40) Understa Compute Applicatwith Blue<-IX
creation.Hence,an objectis referredtoas an instanCeofa class.
States orAttributesforthe objectsofthat class.
hence calleda blue printfora setof objects.