-1

I have declared member variables of a class in 2 separate way:

Class MyClass
{
 int x,y;
}

Class YourClass
{
 int x;
 int y;
}

What is the difference between these two declaration?

  • The first one uses one line of text and the second one uses two lines of text. – barak manos Aug 16 '14 at 07:28
  • ...and of course, `x` and `y` can have different types in the second example. ;-) – T.J. Crowder Aug 16 '14 at 07:40
  • 1
    This question appears to be off-topic because it is not a problem and very well explained in all the languages that support both of these syntaxes. –  Aug 16 '14 at 07:49

2 Answers2

0

There is no difference between two approach.

First approach data type is common for all of its variable.

For readability second approach look nice.

Siva Kumar
  • 1,983
  • 3
  • 14
  • 26
0

There isn't any difference technically.

But it is choice of programmer to declare as how he/she feels is comfortable to read. Second choice would be more readable when you have numerous fields (POJOs) where could easily get lost reading the elements :)

Maas
  • 1,317
  • 9
  • 20