When Java creates an instance, the instance variables in it are first initialized ???

Source: Internet
Author: User

Package cn.com. ch09;

Public class lamptest {
Public lamptest (){
System. Out. println ("construct lamp ...");
}
Public void lidid (){
System. Out. println ("glow ...");
}
Public static void main (string [] ARGs ){

System. Out. println ("creating incandescent ...");
Incandecentlamp ilamp = new incandecentlamp ();
System. Out. println ("creating fluorescent lights ...");
Luorescentlamp LL = new luorescentlamp ();
System. Out. println ("creating energy-saving lamps ...");
Energysavinglamp El = new energysavinglamp ();
}

}
Class filament {

Public filament (){
System. Out. println ("starting to construct filament ..");
}
}
Class energysavinglamp extends luorescentlamp
{
Public energysavinglamp (){
System. Out. println ("start creating energy-saving Lamp ...");
}
}
Class incandecentlamp extends lamptest {
Private filament = new filament ();
// Initialize the instance first. This is initialized ??????????????????

Public incandecentlamp (){
System. Out. println ("start creating incandescent ...");
}

Public filament getfilament (){
Return filament;
}

Public void setfilament (filament ){
This. Filament = filament;
}
}
Class luorescentlamp extends lamptest
{
Public luorescentlamp (){
System. Out. println ("start creating fluorescent lights ...");
}
Private Static filament = new filament ();
Public static filament getfilament (){
Return filament;
}
Public static void setfilament (filament ){
Luorescentlamp. Filament = filament;
}

}

Package cn.com. ch09; public class lamptest {public lamptest () {system. out. println ("construct lamp... ");} public void likes () {system. out. println ("glow... ");} public static void main (string [] ARGs) {system. out. println ("create incandescent... "); incandecentlamp ilamp = new incandecentlamp (); system. out. println ("creating fluorescent lights... "); luorescentlamp LL = new luorescentlamp (); system. out. println ("creating energy-saving lamps... "); energysavinglamp El = new energysavinglamp () ;}} Class filament {public filament () {system. out. println ("start to construct filament .. ") ;}} class energysavinglamp extends luorescentlamp {public energysavinglamp () {system. out. println ("start creating energy-saving Lamp... ") ;}} class incandecentlamp extends lamptest {private filament = new filament (); // initialize the instance first. This is initialized ?????????????????? Public incandecentlamp () {system. out. println ("start creating incandescent... ");} public filament getfilament () {return filament;} public void setfilament (filament) {This. filament = filament;} class luorescentlamp extends lamptest {public luorescentlamp () {system. out. println ("start creating fluorescent lights... ");} Private Static filament = new filament (); public static filament getfilament () {return filament;} public static void setfilament (filament) {luorescentlamp. filament = filament ;}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.