constructor.java~39~

来自「提供了常用的JAVA技术的示例」· JAVA~39~ 代码 · 共 51 行

JAVA~39~
51
字号
package Constructor;class ConstructorTest {  private int x;  private double y;  private boolean z;  private char c='k';  ConstructorTest(){  // 定义 没有 参数 的 构造方法      x=1;      y=0.1;  }  ConstructorTest(int x){      //x=34;      this.x=x;  }  ConstructorTest(double y){      this.y=y;  }  ConstructorTest(int x,double y){      this.x=x;      this.y=y;  }  ConstructorTest(boolean z){      this.z=z;  }  ConstructorTest(char c){      this.c=c;      //c='m';  }  void show(){      System.out.println("x="+x+"   y="+y+"   z="+z+"  c="+c);  }}public class Constructor{  public static void main(String[] args){    ConstructorTest co1=new ConstructorTest();    ConstructorTest co2=new ConstructorTest(3);    ConstructorTest co3=new ConstructorTest(9.0);    ConstructorTest co4=new ConstructorTest(5,5.9);    ConstructorTest co5=new ConstructorTest(true);    ConstructorTest co6=new ConstructorTest('h');    co1.show();    co2.show();    co3.show();    co4.show();    co5.show();    co6.show();  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?