Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

java's flow of control

Status
Not open for further replies.

cat5ive

MIS
Dec 3, 2004
184
US
Hi,

I'm trying to learn java and I don't understand the flow here? When will the statement in red get excecuted?
Thanks in advance.
Code:
public class Registration                               
{   [COLOR=red]
                                                    
    private AttendeeList attendeeList = new AttendeeList
      [/color]
                                                  
    public void run()                                   
    {          
        //do something
     }

     public static void main()
     {   
         System.out.println("Welcome to class Regist.");
         Registration register = new Registration();
         register.run();
                                     
     }
}
 
When an object gets instantiated, that is, new Registration(), all its internal variables are also initialized.

If you have
Code:
private AttendeeList attendeeList = null;

will be initialized to a null value. In your case, a new object will be constructed.

Cheers,

Dian
 
Code:
public class Registration                               
{   
                                                    
    private AttendeeList attendeeList = new AttendeeList[red];

  public Registration()
  {
     //statment here comes AFTER the initalization in question
  }

[/red]
      
                                                  
    public void run()                                   
    {          
        //do something
     }

     public static void main()
     {   
         System.out.println("Welcome to class Regist.");
         Registration register = [green]new Registration()[/green];
         register.run();
                                     
     }
}
Red code I added, green is When it happens. The stuff in the constructor (if a constructor is present) happens after the in line init stuff.

[plug=shameless]
[/plug]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top