info.name
and info.phone
are changing after passing to defaultEntry(Info infoObject)
but reference not changing to null why? can anybody please explain this scenario as well as working of java methods. Is there any difference between c functions and java methods working mechanism?
Thanks in advance :)
class Info {
String name = "Sagar Pudi";
String phone = "9999999999";
}
public class MemberDetails {
public void defaultEntry(Info infoObject) {
infoObject.name = "DEFAULT_MEMBER";
infoObject.phone = "NO_PHONE";
infoObject = null;
}
public static void main(String[] args) {
Info info = new Info();
System.out.println("Before : " + info.name + "<->" + info.phone);
MemberDetails md = new MemberDetails();
md.defaultEntry(info);
System.out.println("After : " + info.name + "<->" + info.phone);
if (info != null)
System.out.println("info is still an object of " + info.getClass());
}
}
Output:
Before : Sagar Pudi<->9999999999
After : DEFAULT_MEMBER<->NO_PHONE
info is still an object of class Info