The moose likes Beginning Java and the fly likes What is the purpose of code Emp e2=e1; and what is the benefit of this. Give output also of the prog Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

What is the purpose of code Emp e2=e1; and what is the benefit of this. Give output also of the prog

Neeraj Goyal
Greenhorn

Joined: Feb 01, 2012
Posts: 2
class Emp
{
String name;
int salary;
void get(String s1,int s2)
{
name=s1;
salary=s2;
}
void show()
{
System.out.println(name);
System.out.println(salary);
}

public static void main(String... s)
{
Emp e1=new Emp();
e1.get("neeraj",20000);
e1.show();
Emp e2=e1;
e2.show();
e2.get("vikram",2000);

}
}
Soumyajit Hazra
Ranch Hand

Joined: Jun 26, 2007
Posts: 135
What's stopping you from running the code and checking the output by yourself?


Java Programmer | SCJP 1.5 | SCWCD 1.4
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 7602

Almost similar to http://www.coderanch.com/t/566150/java/java/want-know-benefit-reference-variable
Let us continue the discussion there


[Donate a pint, save a life!] [How to ask questions]
 
IntelliJ Java IDE
 
subject: What is the purpose of code Emp e2=e1; and what is the benefit of this. Give output also of the prog
 
Threads others viewed
writing a class object in session variable in jsp
permanent memory???
error in my code?
reference id
Sorting String List
Two Laptop Bag