Tuesday 11 September 2018

Class & Objects




Now, we are trying to understand the CLASS & OBJECTS...

Let's Take an Example, and Try to Understand it.

Suppose, You want a 10 Table & Chair for your Tuition Class
You just go to the near Carpenter Shop and said I want 10 Tables and chairs for my tuition classes.
So, They offer you a chair and asks you some questions about your table and chair requirements like-  size of the table (length and width), glass or wooden table, what about the table legs wooden or iron,
the colour of the table or leg, etc.
and he wrote down all the details in the piece of paper for remembrance.



and After 10 Days your Chair is ready .. Just go to the shop, pay the balance (Money) get all the tables and chairs.

Now,

The piece of paper (in that all the details are written about table and chair )  is called -- CLASS.

And

The real Tables and Chair That you receive after 10 Days is called -- OBJECTS.


 ********************************************************************************

One more STORY, To understand the concept better...

Hey, Friends!,  Meet my friend JONE.


First Name                      - Jone
Middle Name                  - Sonu
Last Name                       - Sena
Father's Name                 - Harish Sena
Mother's Name               - Sumitha Sena
Gender                             - Male
Qualification                    - B.Tech (CSE)
DOB                                - 12th - December - 1990
Height                              -  163 cm
Weight                              -  78 kg
Address                            - #45, 23/430 , Delhi
Contact No.                      - 8950XXXXXX
Working in                       -  XYZ MNC
Status                               - Un married
Bank Account Name         - ABC Bank
Bank Account Number    - 335957XXXXXX455

(like that Jone has many more Details/Properties ...)


Question - If you are a developer and you have to make a software for Bank, Tuition Insitute and Hospital to Know Your Customer, then what kind of details you are looking for?

Answer -

# For Bank

class KYC
{
Customer Name -
Customer Father's Name -
Bank Account No. -
Address -
Contact No. -
}

# For Tuition Institute 

class KYC
{
Student Name -
Father's Name -
Course -
Fee Status -
Address -
Contact No. -
}

# For Hospital

class KYC
{
Patient Name -
Father's Name -
Age -
Height -
Weight -
Problem -
Address -
Contact No. -
}


Question - Now, Question arise Which kind of information you have to write inside the class?

Answer - We have to write that information which is important for that application (it depends on the perspective of a viewer).
Jone has many properties but in a different application, we acquire (take) different kind of information, so it depends on application to application.




Definition Of A CLASS

A class is a templet where we describe the properties and behaviour of an object.

0r

A class is a collection of objects which similar properties and behaviour. 

0r

A class is a group of a common object. It is a user defined data type. It Contains variables and functions. The class defines all the common properties of the different objects that belong to them.
0r

A class is a blueprint or prototype that defines the variables and the methods (functions) common to all objects.

0r 

Class a template/blueprint that describes the behaviour/state that the object of its type support.




Definition Of AN OBJECT


*Object: It is the instance of a class. 

0r 

An object is a specimen of a class. Software objects are often used to model real-world objects you find in everyday life.

0r 

An object is nothing but a self-contained component which consists of methods and properties to make a particular type of data useful. Object determines the behaviour of the class. When you send a message to an object, you are asking the object to invoke or execute one of its methods.



# Syntax of class


For Example - 

class Fan {
// properties 
//and
// behaviour
}


# Syntax of Object

- It is a two step process...

1st Step -


For Example -  

Fan f ;


2nd Step - 


For Example - 

f = new Fan();



These two steps you can also do in a single line - By combining



For Example -

Fan f  =  new Fan() ;







No comments:

Post a Comment