Bahaa Salaheldin
Bahaa Salaheldin

Reputation: 529

What's the difference between object and variable?

I'm confused.. what's the difference between SQLConnection connection=new SQLConnection(); and SQLConnection connection;? what's the situation I should use one of both?

Upvotes: 0

Views: 58

Answers (1)

Rahul
Rahul

Reputation: 77866

First one: SQLConnection connection=new SQLConnection(); is variable declaration and initialization at the same time (Eager Initialization) but the later part SQLConnection connection; is just the variable declaration since you have decided to initialize it sometime later when it's actually needed to create a SQLConnection instance.

You should be using the later one SQLConnection connection; if you want to declare it at class level as a global connection variable which say then can be used by multiple methods / event handler/.

Upvotes: 1

Related Questions