有参构造的用处在于构造一个对象的同时初始化它的属性。

package 构造函数;

/*
 * 不同参数构的对象问题
 */

public class TestConstractot {
    String name ;
    private Number num ;
    
    public TestConstractot(String name,Number num){
        this.name = name;
        this.num = num;
    }
    
    public static void main(String args[]){
        TestConstractot constrctor = new TestConstractot("les", 1);
        TestConstractot constrctor2 = new TestConstractot("les", 1);
    }
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-13
  • 2021-09-03
  • 2022-12-23
  • 2021-08-29
  • 2022-02-26
  • 2021-09-29
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-22
  • 2022-12-23
相关资源
相似解决方案