Total members 9950 | Gratitudes |It is currently Sat Feb 11, 2012 3:17 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Question
 Question subject: Passing a Reference Variable
PostPosted: Thu Feb 05, 2009 12:31 am 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2103
Location: Earth
Has thanked: 39 time
Have thanks: 56 time

Passing a Reference Variable :
When you pass a reference variables to a method ,you pass a copy of the passed reference variables .Both references points to the same object

Note : Both references can change a member in the object .

Example :
Code:
public class Main {

     
           
    public static void main(String[] args) {
       
          Main test=new Main();
          circle newc=new circle();
          newc.setR(43);
          System.out.println("Before calling method : R="+newc.getR());
          test.changeR(newc);
          System.out.println("After calling method : R="+newc.getR());
         
    }
    public void changeR(circle c)
           
    {
        c.setR(32);
        c=null;
    }
}

interface shape
{
     
     public void Draw();
     
     
}
class circle implements shape
{
    private int R;
    public void Draw() {
        System.out.println("Drawing Circle here");
    }

    public void setR(int R) {
        this.R = R;
    }

    public int getR() {
        return R;
    }
   
     
     
}


The result :
Code:
Before calling method : R=43
After calling method : R=32

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  


 Similar topics
 Topic title   Forum   Author   Comments 
 methods with variable arguments list  Java examples  msi_333  1
 How can I pass a PHP variable to a window.onload event funct  PHP  Gilbertomorden  1
 Id reference annotation relationship  JPA  msi_333  0
 Reference between two schemas in oracle  General Discussion  msi_333  0
 Passing arrays as function parameter in java  Java examples  msi_333  0

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 3 guests



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team