English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Is this a proper way to initialize these variables

int x, sum;

2007-08-13 09:35:15 · 4 answers · asked by dingdong 1 in Computers & Internet Programming & Design

4 answers

this is variable declaration, without a assignment of value.

but integer is a primitive data type, with a default value (0)

2007-08-13 09:42:10 · answer #1 · answered by Anonymous · 0 1

yes, that is fine for java. it's good practice (IMO from days of C/C++) to initialize your variables when declared -- int x = 0, sum = 0 ; , but what you wrote is also technically correct.

2007-08-13 09:41:35 · answer #2 · answered by mdigitale 7 · 0 0

no,this is a declaration, no an assignment of value.
an assignment is for exsample:

int x;
x = 10;

or

int x=10; <---- An Assignment and declaration

Integer is a primitive data type, with a default value (0)

2007-08-13 13:36:52 · answer #3 · answered by T4n|n0 Ru|3z 3 · 0 0

if that variable is used in expressions wihtout getting assigned anywhere,

the javac throws this msg

The variable may not have been initialized.

Try this and understand.

All the Best.

2007-08-14 03:34:16 · answer #4 · answered by Siva 3 · 0 0

fedest.com, questions and answers