Java instance variables initialization with method

前端 未结 6 787
太阳男子
太阳男子 2021-01-11 09:43

I am a little bit confused about the following piece of code:

public class Test{

  int x = giveH();
  int h = 29;

  public int giveH(){
     return h;
  }
         


        
6条回答
  •  情话喂你
    2021-01-11 10:23

    Once declared, all the array elements store their default values. Elements in an array that store objects default to null. Elements of an array that store primitive data types store: 0 for integer types (byte, short, int,long); 0.0 for decimal types (float and double); false for boolean; \u0000 for char data.

    Actauls values will come only when we give initialize them

提交回复
热议问题