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 )