Wednesday, May 16, 2012

ကဲ ဘာလဲေျပာ။



public class Person {
        private String name;
private String age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
}
____________________________________________________


public class testObj {

public Person personA=new Person();
public static void chageStr (Person personB){
testObj tstObj=new testObj();
tstObj.personA.setName("I am Person B");
}

public static void main(String[] args) {
System.out.println("What does I hold now?");
testObj tstObj=new testObj();
chageStr (tstObj.personA);
System.out.println(""+tstObj.personA.getName());
}
}
_________________________________________
highlight လုပ္ထားတဲ႔ System out ကေနဘာထြက္မလဲေမးပါတယ္။
Ans: null
_________________________________________

ဒုတိယတစ္ခု နည္းနည္းျပင္ေရးလုိက္ပါတယ္။


public class testObj {
static Person personA=new Person();
public static void chageStr (Person personB){
personA.setName("I am Person B");
}

public static void main(String[] args) {
System.out.println("What does I hold now?");
chageStr (personA);
System.out.println(""+personA.getName());
}
}

_________________________________________
highlight လုပ္ထားတဲ႔ System out ကေနဘာထြက္မလဲေမးပါတယ္။
Ans:  I am Person B
_________________________________________


static Bean Obj ေတြသံုးၾကသလားမသိပါဘူး။ အျပင္မွာသံုးေနၾကမဟုတ္ရင္ မသိဘဲမွားေျဖမိဖို႕မ်ားပါတယ္။



No comments: