How is typing:
public class Example
{
private Cat whiskers;
public void makeCat()
{
whiskers = new Cat();
}
}
different than:
public class Example
{
public void makeCat()
{
Cat whiskers = new Cat();
}
}
it seems that the first example is more work because you can now only create Cat objects named whiskers from it. Why declare it at all?
In the first you are declaring a private variable that may be used within the same instance by other methods (or properties). However, in your second example you are just declaring a variable with a local scope, in other words, this variable will only be visible within
makeCat().