0

In order to save space and reduce redundancy in Java. Is it okay to do

public static double a, b, c = 0.0;

instead of

public static double a = 0.0;
public static double b = 0.0;
public static double c = 0.0;

? Also if the variables have different values, is it okay to do

public static double a = 0.0, b = 1.0, c = 2.0;
kevin_b
  • 803
  • 4
  • 16
  • 34
  • 1
    Possible duplicate of [Java one line variable declaration?](http://stackoverflow.com/questions/20117500/java-one-line-variable-declaration) – Arun Xavier Feb 23 '16 at 07:00
  • http://stackoverflow.com/questions/6202818/initializing-multiple-variables-to-the-same-value-in-java – Vicky Thakor Feb 23 '16 at 07:01
  • 1
    Considering that this syntactical sugar goes away at compile time... it doesn't really matter. – ifly6 Feb 23 '16 at 07:05

1 Answers1

1

It should be:

public static double a = 0.0, b = 0.0, c = 0.0;

This way they are equivalent.
Otherwise, you rely on default initialization that is, of course, as if you had assigned 0.0 for a double, but is it is usually considered bad practice.

skypjack
  • 49,335
  • 19
  • 95
  • 187