Difference object instantiation inside constructor and outside constructor?

  • Thread starter Thread starter Satish12321
  • Start date Start date
S

Satish12321

Guest
Is there any difference between the following two object instantiation?

Case 1: Instantiation inside constructor

Class Engine
{
}

Class Car
{
public Engine engine;

public Car()
{
engine = new Engine();
}
}

Case 2: Instantiation outside constructor

Class Engine
{
}

Class Car
{
public Engine engine = new Engine();

public Car()
{
//other lines
}
}

Continue reading...
 

Similar threads

Back
Top