Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
RHCSA, RHCE, AWS, Docker, Kubernetes Training
Sanjeewani95
Updated:
Tuesday at 10:28 AM
🛡️ Kaspersky Antivirus – 1 Year / 1 Device | Rs. 2,300 | Only 9 Left
KSPathirana
Updated:
Sep 7, 2026
Ad icon
Professional CCTV Installation Service
Techguy231
Updated:
Sep 6, 2026
Ad icon
I'll research & write an article - Rs. 2000 onwards
Blogerwiki
Updated:
Sep 3, 2026
House Plan
lenura
Updated:
Sep 2, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
Education
ElaKiri Programmer's Club
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="DooA" data-source="post: 16781013" data-attributes="member: 362085"><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px">ජාවා වල විතරක් නෙමෙයි ගොඩක් languages වල method වලට parameters pass කරද්දී variable වලට reference එක පාස් කරනේ නැනේ .</span></p><p><span style="font-size: 18px">Value එක විතරයි නේ පාස් කරන්නේ. එත් මචං මට පොඩි අවුලක් තියෙනවා. පල්ලෙහා තියෙන එක බලපන්. එකේ main method එකේදී Object කියල class එකේ instance එකක් හදලා DoThings කියල class එකට යවනවා. එතකොට යන්න ඕනේ actual instance වෙනුවට තියෙන instance එකේ copy එකක් නේ. එතකොට වෙන්න ඕනේ DoThing class එකේදී යවන instance එකේ variable එක වෙනස් (100) කරලා print කරනවා. එතකොට වෙනස් කරපු value එක ප්රින්ට් වෙනවා එක හරි. එත් දැන් main එකේදී තියෙන instance එකේ value එක display කරාම print වෙන්න ඕනේ 10 යි කියලා. මොකද default value එක 10 තියෙන්නේ. අනික method එකට pass කරන්නේ actual object එක නෙමෙයි. එක නිසා method එකේදී මොනවා කරත් main එකේ තියෙන object එකට අදාලා නෑනේ. </span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px">එත වෙන්නේ අනික් පැත්ත main එකේ තියෙන object එකත් වෙනස් වෙනවා.</span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px">එත මේක primitive data type වල නම් main එකේ තියෙන variable එක වෙනස් වෙන්නේ නෑ. ඒ කියන්නේ primitive data type වලදී යවන්නේ actual variable එක නෙමෙයි. නමුත් instance වලදී යවන්නේ actual එකද. </span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px">මේක හෙන අවුල් බන්. </span></p><p></p><p>[CODE]</p><p></p><p>public class Main {</p><p></p><p> public static void main(String[] args) {</p><p> Object obj = new Object();</p><p></p><p> new DoThing(obj); // send instance to dothing class</p><p></p><p> obj.display(); // print current value . this must be 10</p><p></p><p> }</p><p></p><p>}</p><p></p><p>[/CODE]</p><p></p><p></p><p>[CODE]</p><p>class DoThing {</p><p></p><p> public DoThing(Object object) {</p><p> </p><p> object.setVALUE(100); // set value to 100</p><p> </p><p> object.display(); // print it</p><p> }</p><p>}</p><p></p><p>[/CODE]</p><p></p><p>[CODE]class Object {</p><p></p><p> private int VALUE = 10;</p><p></p><p> public void display() {</p><p> System.out.println(VALUE);</p><p> }</p><p></p><p> public void setVALUE(int a) {</p><p> VALUE = a;</p><p> }</p><p></p><p> public int getVALUE() {</p><p> return VALUE;</p><p> }</p><p></p><p>}[/CODE]</p></blockquote><p></p>
[QUOTE="DooA, post: 16781013, member: 362085"] [SIZE="5"] ජාවා වල විතරක් නෙමෙයි ගොඩක් languages වල method වලට parameters pass කරද්දී variable වලට reference එක පාස් කරනේ නැනේ . Value එක විතරයි නේ පාස් කරන්නේ. එත් මචං මට පොඩි අවුලක් තියෙනවා. පල්ලෙහා තියෙන එක බලපන්. එකේ main method එකේදී Object කියල class එකේ instance එකක් හදලා DoThings කියල class එකට යවනවා. එතකොට යන්න ඕනේ actual instance වෙනුවට තියෙන instance එකේ copy එකක් නේ. එතකොට වෙන්න ඕනේ DoThing class එකේදී යවන instance එකේ variable එක වෙනස් (100) කරලා print කරනවා. එතකොට වෙනස් කරපු value එක ප්රින්ට් වෙනවා එක හරි. එත් දැන් main එකේදී තියෙන instance එකේ value එක display කරාම print වෙන්න ඕනේ 10 යි කියලා. මොකද default value එක 10 තියෙන්නේ. අනික method එකට pass කරන්නේ actual object එක නෙමෙයි. එක නිසා method එකේදී මොනවා කරත් main එකේ තියෙන object එකට අදාලා නෑනේ. එත වෙන්නේ අනික් පැත්ත main එකේ තියෙන object එකත් වෙනස් වෙනවා. එත මේක primitive data type වල නම් main එකේ තියෙන variable එක වෙනස් වෙන්නේ නෑ. ඒ කියන්නේ primitive data type වලදී යවන්නේ actual variable එක නෙමෙයි. නමුත් instance වලදී යවන්නේ actual එකද. මේක හෙන අවුල් බන්. [/SIZE] [CODE] public class Main { public static void main(String[] args) { Object obj = new Object(); new DoThing(obj); // send instance to dothing class obj.display(); // print current value . this must be 10 } } [/CODE] [CODE] class DoThing { public DoThing(Object object) { object.setVALUE(100); // set value to 100 object.display(); // print it } } [/CODE] [CODE]class Object { private int VALUE = 10; public void display() { System.out.println(VALUE); } public void setVALUE(int a) { VALUE = a; } public int getVALUE() { return VALUE; } }[/CODE] [/QUOTE]
Insert quotes…
Verification
Haya warak paha keeyada? (haya wadi kireema paha)
Post reply
Top
Bottom