Objects and Classes In JAVA


Object:-    

            In real world scenario there exist different type of objects, basically objects are the thing which have some properties and some behaviors. 

      like a smartphone, a smartphone is the object which have different properties and behaviors , a smartphone have properties like its color, manufacturer, RAM size, ROM, processor etc. and the behavior of smartphones are calling, net surfing, calculation, data storage etc. 
       we can take an another example of an object. We take a scenario of an Employee. An employee is the object which has some properties like his name, age , company name, salary ,department etc . it can have behaviors too like production, how employee work, work over projects , growth of employee in the company, employee's work rate etc. 
           Like policeman is an object , A policeman have properties like his name, age, department, and work place and his behaviors is investigation, finding thieves, bring him to court etc.

So, basically this concepts of object is come from the real world. 


             JAVA is the programming language which can implements these concepts of objects in  programming. Which totally based on these object related work so that JAVA represent the object oriented approach of programming. Behaviors of and object leads to change in the properties of an objects. 
  


Before going to programming part of object we must know about the class of objects. 


Class:-

                Class is the entity which represent similar type of objects. Like, there can be many employee in a company, there would be a single class Employee which is representing the objects- employees. It tells and store data about there name, age,  profile and there behavior too like there project works, production, there growth etc.


              Basically, class is the entity which represents the properties and behaviors of objects. All the objects represented by a class is of similar type. So, finally we can say that Class is the representation of objects.





Since java follows object oriented approach of programming, so it is possible to program these classes and objects in Java. How these classes and objects can be represented in java ? let's have a look at it.

Suppose Employee is the class which is representing employee's properties and behaviors then employee_number_1,  employee_number_2, and so on, all these number of employees are the objects of the class Employee. because they all have name, age, salary, department and there project work in company, growth , and production.
so first we must know how to represent class in JAVA.
to implement a class in JAVA there is use of a keyword Class which have body enclosed within braces. and within which there is representation of properties and behaviors of objects of the class. 

 Syntax:  

               Class Class_name {

                                                  properties;
                                                 
                                                  behaviours;
                                          
                                              }


In object oriented programming, properties of an object is represented by variables. and behaviors are represented by the functions. Functions are responsible for any change in the properties of the object.

  properties are reprented like, 

                                            String name;
                                                 int age;
                                                 int salary;

and the behaviours are represented like, 

                              void production( )
                                {
                                 body;
                                  }
                              int work_rate( int lwrate)
                               { 
                                  body;
                                }

there should be two functions or methods in the class which will read and show the properties of objects.

                         
                            void getEmpDetails()
                                { 
                                      body;
                                 }
                           void showEmpDetails()
                               {
                                   body;
                                }

so finally the class will represented as
                         
   Class Employee{    
                                      //properties
    
                                            String name;
                                                 int age;
                                                 int salary;

                                     //behaviors
     
                           void getEmpDetails()
                                { 
                                      body;
                                 }

                           void showEmpDetails()
                               {
                                   body;
                                }

                           void production( )
                                {
                                 body;
                                  }

                          int work_rate( int last_work_rate)
                               { 
                                  body;
                               }                             

                      } 

So, this is the Way to declare the class for objects. Now lets have a look at the declaration of the object which is necessary to use this class.
          
 Syntax: 


                       Class_name Object_name = new Class_name( );


so for to declare the object for class Employee


                       Employee emp1 = new Employee( );



On the execution of the above statement there will be creation of object in the memory which have the name emp1. There use of new operator in declaration syntax of object, this new operator is used for the memory allocation of object in RAM. 

The functions are also called methods in JAVA.

For further OOPs concepts and how a object uses the class, keep visiting 


              https://kailashkumar210.blogspot.in/

Comments

Popular posts from this blog

Screen Saver Development In C language

Installing MySQL(5.7) on MacOS (Monterey)