Java基础学习篇---------this的学习

1.使用this调用构造方法市一定放在构造方法的首行

2.使用this调用构造方法时一定流出调用的出口

public class MyClass {

public MyClass(){
System.out.printf("调用无参数的构造方法");
}
public MyClass(String name) {
this();
System.out.printf("调用一个参数的构造方法");
}
public MyClass(String name , int a) {
this(name);
System.out.printf("调用两个参数的构造方法");
}
public static void main(String[] args){
MyClass myClass = new MyClass("zz" , 20);
}

public static String initCap(String s){
return s.substring(0, 1).toUpperCase().concat(s.substring(1));
}
}

猜你喜欢

转载自www.cnblogs.com/liunx1109/p/9780738.html