I want to set objects equal to one and other, but when i do so i receive the following error:
"Exception in thread "main" java.lang.Error: Unresolved compilation problems: Duplicate local variable current Duplicate local variable h1 at objectx3Problem.mainmethod.main(mainmethod.java:15)"
Here is my source code:
public class mainmethod {
public static void main(String[] args) {
// TODO Auto-generated method stub
human h1 = new human();
human h2 = new human();
human current = new human();
System.out.println(h1.getHealth());
human current = h1; // error here
current.DecreaseHealth();
human h1 = current; //error here
System.out.println("h1 has " + h1.getHealth() + "health");
}
}
and
public class human {
private int Health = 100;
public int getHealth(){return Health;}
public void setHealth(int Health){this.Health = Health;}
public void DecreaseHealth()
{
Health = Health - 5;
}
}
I have read the same question here setting objects equal to eachother (java),
but I do not understand how the top answer and my approach are different.
Thanks in advance