-3

In C a static variable or a variable in a file scope is initialized to 0 when declared and a variable declared in a function that is not initialized has random data. Does this happen in Java too somehow?

Note: I refer only to primitive types not objects.

Daniel Oliveira
  • 1,280
  • 14
  • 36
  • 1
    Difference between static in java and c. Just so you know there is a difference :) http://stackoverflow.com/questions/728534/whats-the-equivalent-of-cs-static-keyword-in-java – Murillio4 Oct 01 '16 at 23:27

1 Answers1

3

Yes java also has default values for primitive data types. Default Value (for fields)

  • byte : 0
  • short : 0
  • int : 0
  • long. : 0L
  • float : 0.0f
  • double : 0.0d
  • char : ‘u0000’
  • boolean : false
  • String (or any object) : null
nhouser9
  • 6,730
  • 3
  • 21
  • 42
Osama Khalid
  • 307
  • 4
  • 14