Which is better or which is right way to do this, can you also give explanation (I didn’t know what search term to use on Google).
First way:
Public Class A()
{
Paint _paint _test;
public void running()
{
_test = new Paint();
//use paint
}
}
OR
Public Class B()
{
Paint _paint _test = new Paint();
public void running()
{
//use paint
}
}
Thanks
The first way is better when you might (maybe in the future) possibly want to pass parameters to the member’s constructor, e.g:
The second way is better when you know you will never want to pass parameters to the member’s constructor and you have multiple constructors that all need to initialize this member, e.g: