this()方法的使用

class exercise
{
    int m,n;
    String a,b;
    exercise()
     { }
    exercise(int m,String a)
     {
         this.m=m;
         this.a=a;
     }
    exercise(int m, int n,String a,String b)
     {
          this.m=m;
          this.n=n;
          this.a=a;
          this.b=b;
      }
  }
  public class MyTest
   {
       public static void main(String[] args)
      {
          exercise f1=new exercise();
          exercise f2=new exercise(12,"zxcvv");
          exercise f3=new exercise(23,43,"asdf","ghhgff");
          System.out.println("m="+f1.m+"n="+f1.n+"a="+f1.a+"b="+f1.b);
          System.out.println("m="+f2.m+"a="+f2.a);
          System.out.println("m="+f3.m+"n="+f3.n+"a="+f3.a+"b="+f3.b);
       }
  }

运行效果:

posted on 2017-05-21 14:52  Iitb  阅读(343)  评论(0)    收藏  举报

导航