class father
{
}
class son extends father
{
public static void main(String[] args)
{
son s=new son();//这里先产生一个父类,再产生一个子类吗?
}
}
learn the more confused,
seeking authoritative answers
------ Solution - -------------------------------------------
is to perform the constructor of the parent class , instead of generating a parent class instance
------ Solution --------------------------- -----------------
where's son did not father
your subclass constructor calls the constructor of the parent class !
------ Solution ------------------------------------ --------
class 圣父 {}
class 圣子 extends 圣父 {}
class 圣灵 extends 圣子 {}
The following code will not have a single one with a matter of the Father / Son , who is Trinity
圣灵 a = new 圣灵();
------ Solution ------------------------------------- -------
of course , the real " Trinity" , above the three , not extends relationship
------ Solution -------------- ------------------------------
after creating an instance of a subclass of class initialization method will call the parent class initialization method ( apart from java.lang.Object class because no parent class java.lang.Object ) , and this call will be traced step by step until the initialization method of java.lang.Object .
This place is the initialization method instead of the constructor , because the constructor is relative to java source code , the compiled class files and initialization method is that "
The third part is the java source code constructor code , java source code, there are several construction methods , then there are several class file initialization method , the compiler will first portion and the second were copied to the front part of each initialization method , then the corresponding code constructor initialization method parameters are copied to the appropriate initialization method
call the initialization method does not generate objects
Imagine your parent class is an abstract class , the abstract class and how it can produce objects
------ For reference only --------------- ------------------------
call the constructor does not necessarily generate objects?
wait authority
------ For reference only ---------------------------------------
mean that the Holy Spirit will first generate a Father and the Holy Spirit produces a right ? Why do some people say just call the constructor , but did not have a parent class object ?
------ For reference only -------------------------------------- -
mean that the Holy Spirit will first generate a Father and the Holy Spirit produces a right ? Why do some people say just call the constructor , but did not have a parent class object ?
I said , " The Holy Spirit will generate a first produce a Father and the Holy Spirit do "
------ For reference only ---------------- -----------------------
I said , " The Holy Spirit will generate a first produce a Father and the Holy Spirit you" yet ?
------ For reference only -------------------------------------- -
I got it wrong ~
没有评论:
发表评论