- public class test3 {
-
- /**
-
- * @param args
-
- */
-
- public static void main(String[] args) {
-
- // TODO Auto-generated method stub
-
- A a = new A();
-
- a.mehtod1();
-
- System.out.println(a.isRight1());
-
- a.mehtod2();
-
- System.out.println(a.isRight2());
-
- }
-
- }
-
- class A{
-
- private boolean isRight1 = false;
-
- private boolean isRight2 = false;
-
- public boolean isRight1() {
-
- return isRight1;
-
- }
-
- public boolean isRight2() {
-
- return isRight2;
-
- }
-
-
- public A() {
-
- }
-
-
- //只修改right1,不动right2
-
- void mehtod1(){
-
- a(isRight1);
-
- }
-
-
- void mehtod2(){
-
- a(isRight2);
-
- }
-
-
- void a(boolean isRight){
- if(isRight==this.isRight1){ //通过==判断传过来的值是否与该类中的值地址相等,如果相等,就把该类中的值改成true;
- this.isRight1=true;
- }else if(isRight==this.isRight2){
- this.isRight2=true;
- }
- }
- }
复制代码 这样就可以了 |