what actually happens when u declare the objects..............!!

                               Declaration of objects  


  • well what that happens when we declare an object
  • objects are those that contains the ability to access the methods and variables declared in class
  • objects are the vaiables of class
  •  "object" refers to a particular instance of a class where the object can be a combination of variables, functions, and data structures. 
so our motto was what actually happens when we declare an object


  • an object has two parts  one is the data that it remembers and other the actions that it has to perform.
  • for eg objects is the collection of different types of variables of class so which all members are included in it it has to remember and which method it has to call i.e. given action by the user.
  • the lifetime of the variable and the value is till the object is alive.i.e till the logical end of the program.

                       logical end and abnormal end


  • logical end and the abnormal end are the two ends that should be understood by the programmer logical end is basically the end of the program that is the last curly bracket of the program well that is the same for the abnormal end.
  • so basically the difference between these two is when the program fully executes that is till the last statement we say that the logically end has occured.
  • But when errors occurs specially the rrun time error (exceptions) we talk about in between the run time time when the error occurs the exception is thrown into the screen by the compiler so in between the execution is stopped so semicolon(;) is not executed so the pointer dosent move to execute the next line so the statements after that are not executed .
  • and there comes the abnormal end of the program.
well comming back to our main topic....



  • memory for the members is not allocated when we declare the objects in class 
  • for eg     
                                   class A
                                   {
                                       int a,b;
                                       float d;
                                       char c; 
                                   }

see here by declaring the variables dosent occupy the memory in the stack or heap.


  • but declaring the objects acquires the space in the memory for int a,b i.e 2 bytes for each int variables in c and cpp and 4 bytes for java like wise respectively for float and character.
  • so we can say that no object nothing can happen cant initialize the value for variables and cant call the method .
  • so we can thus prove that cpp is the object oriented language nothing can happen without object the program is lifeless .
  • where as the long coding is done in class and just the declaration of object is in main() 
Now as we declare the object 


  • a refrence is created of the particular object.
  • and memory is allocated in the memory called virtual memory that is stack or heap.
  • refrence is used to invoke the particular function or method as how we could know that this method is called by this object. 
  • refrence of the object is stored in the variable named this that automatically is placed by the compiler first the refrence is stored in this variable and then only by this refrence the object are initliaze .
  • so at the time of creation object the refrence of object is also stored in stack or heap.
  • when we create the object at that time the constructor is called of the particular class(a brief about constructor is given in previous post) .
  • so by calling a constructor we can pass an arguement with an object to call a constructor 
  • a constructor has a automized call at the time of ctreation of objects no explicit calls by the user can be made for it.
  • so constructor is called by the object so what actually happens is the refrence of the object goes with it........ initializes the values..... and returns back the address ..
  • so we can say that the constructor returns the implicit address.. and then the adress of the object is stored in stack or heap.
  • once when object is created its adress is stored now withb that object we can call any method or we can access any variables with it so impicitly its adress travels to call method or to initialize the object.
  • they are also used to call destructor when the scope of the objects gets over and can print any message in destructor as object has been destroyed.

Comments

Popular posts from this blog

State space search / blocks world problem by heuristic approach /TIC TAC TOE

Navigation in Vaadin.

Drag and drop items from one Grid to another