1 Attachment(s)
different instant variable of same class
Hai all
is the values are storing statically and why???????????????
if you run the programme it willl give the output
Name : Anna
Name : Beah
Name : Cris
Id : 1
Name : Cris
Grade : 32.1
Id : 2
Name : Cris
Grade : 32.1
Id : 3
Name : Cris
Grade : 32.1
see the name and grade is setting as static why????????
Q 2)
another programme
public class Testings {
public static void main (String[] args) {
X xx;
X yy;
X zz;
xx=new X();
yy=new X();
zz=new X();
xx.setStudentId(5);
yy.setStudentId(10);
zz.setStudentId(15);
System.out.println (xx.getStudentId());
System.out.println (yy.getStudentId());
System.out.println (zz.getStudentId());
System.out.println (xx.getStudentId());
}
}
class X {
private int studentId;
public int getStudentId()
{
return studentId;
}
/**
* Changes the value of studentId
*/
public void setStudentId(int studentId)
{
this.studentId = studentId;
}
}
the out put is
5
10
15
5
why is like this though the setting is done to a single private int studentId; but done by different instant variable of same class
i'm confused please explain correctly if any on can
thanks