I am trying to understand java class and object relation but facing one problem.
Here I have one simple java bean class:
public class Student {
int id;
String name;
String marks;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMarks() {
return marks;
}
public void setMarks(String marks) {
this.marks = marks;
}
}
And one Editor class:
public class EditStudent {
public static void editStd(Student st){
st.setId(10);
st.setName("editAbleName");
st.setMarks("133");
// return st;
}
I am writing this logic for student object in my program class:
public class TestProgram {
public static void main(String args[]){
System.out.println("main");
Student std = new Student();
std.setId(1);
std.setName("zeeshan");
std.setMarks("44");
EditStudent.editStd(std);
System.out.println("id " +std.getId());
System.out.println("name " +std.getName());
System.out.println("marks " +std.getMarks());
}
}
Output:
main
id 10
name editAbleName
marks 133
I supposed that I will get output values of my object that I set on my test program class but getting output values of those which I set on my EditStudent
class.
Why this happen even I think there is no relation between my std
object and editStudent
Class ?
Please explain me logic occurs behind this logic and process!