Home Field vs field and new object
Reply: 0

Field vs field and new object

user654
1#
user654 Published in May 25, 2018, 7:12 am

I was wondering what is the diffrence between these two situations:

class Cell
{
    Messages msg;

    public void getMessage()
    {
        msg.getMessage();
    }
}

and:

class Cell
{
    Messages msg = new Messages();

    public void getMessage()
    {
        msg.getMessage();
    }
}

I know that in the first example I declared only field, and in the second I declared field, object and assigned object to the field. But in the both situations I can use .getMessage() method in Cell class, so what is diffrence and what should I use?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.386277 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO