java 构造器:
类的构造器是为了创建一个类的实例而存在的
特点:
1.构造器不能有非访问限制性的修饰符例如:final,static,abstract,native,synchonzied等
2.构造器无范围值
3.可以有任何访问性的修饰例如:private,public,protected等
4.必须和类的名称相同
构造器this用法:
/**
* <p>Title: ConstrutsTest.java</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2017</p>
* <p>Company:kehui</p>
* @author jiangcl
* @date 2018年10月20日
* @version 1.0
*/
package com.mvc.test.construct;
/**
* <p>Title: ConstrutsTest</p>
* <p>Description: </p>
* @author jiangcl
* @date 2018年10月20日
*/
public class ConstrutsTest extends FatherConstrutsTest{
private int flag = 10;
public ConstrutsTest(){
System.out.println("construtsTest start");
};
public ConstrutsTest(int y){
//this();
System.out.println("construtsTestY start");
};
public static void main(String[] args) {
ConstrutsTest test = new ConstrutsTest(10);
}
public void test(){
System.out.println("ConstrutsTest start");
}
}
class FatherConstrutsTest {
private int flag = 100;
public FatherConstrutsTest(){
System.out.println("FatherConstrutsTest start");
test(); // 实际上调用的子类的test方法
};
public FatherConstrutsTest(int x){
System.out.println("FatherConstrutsTest start");
}
public void test(){
System.out.println(" FatherConstrutsTest start ");
}
}
1150

被折叠的 条评论
为什么被折叠?



