User Login
Latest Technology Articles
- PCinvent Studio Programming Solutions
- Fedora Core 12 YumEx Problem
- VMware Guest Wide Screen Resolution Problem
- DD-WRT Router Firmware
- OpenVPN AS Client Installation Problem Fix
- Redhat Yum problem
- File Server Solution
- Old C++ Project of ATM Machine
- My Research and Project of the Reversed Array List (Reversed Index Array List)
- My Research of Linear Data Structure
| Object's assignment, storage & grabage |
|
|
| Monday, 29 September 2008 | |
|
Many only know the syntax of the object oriented language, but never think of how it works and how the problem occures. Here is a simple tutorial I am going to write and explain. Suppose we have a Class: Account.java ( Account.cs in the case of C# )......
Account Class:
Now, a class and its methods were done. If we have another class file called "operateAccount.cs" in the same directory of the Account.cs, to create a new object of Account, we will do:
It is same as:
Of course, both object can call the method to access: account1.deposite ( 50.00 );
Ok, so far, the above code should be very well known. But what if we do: Account account1;
Will it generate a compile error or run-time error? No, these syntax are correct.
Account account1
Account is a object data type. So this one is a object varible assigment. int a;At this point, the memory for the variable is allocated, but not value assigned yet. ( Some languages initalize value to 0 by Default) Similarly, this one does the same: Account account1; account1 = new Account(100.00)
The new Account object will not stored in the account1 box. ( Common mistake) GarbageObject will become a grabage where there is no varible referring to it. For example, if we have the account1 object varible, when we say:
Now the account2 will refer to the same object of the account1. Also, if we do method of
At the same time, bother account1 and account2 will have 100 withdrawn. Knowing the object assignment, we are now going to talk about Grabage. We have account1 and account2 variables:
Both refer to different objects. now we do:
Obviously, account 1 and account 2 are now pointing to (referring to) the Account object Where there is 900.00 value stored. So we will never be able to use the Account Object whihc holds the data of 100.00 again. Comments (0)
![]() Write comment
Tags: Technology Programming Irregular Object's assignment storage & grabage java C# object oriented statistic method instance method |
|
| Last Updated ( Tuesday, 30 September 2008 ) |
| < Prev | Next > |
|---|





