Карта сайта Интеллектуальная поисковая системаДобавить свою ссылку по ключевому запросуПоисковая система v3.kz поможет ускорить индексацию вашего сайта выводит в Топ |
|
Everything in Java not explicitly set to something, is initialized to a zero value. For references (anything that holds an object) that is null. For int/short/byte that is a 0. For float/double that is a 0.0. For booleans that is a false. When you create an array of something, all entries are also zeroed. Note that some of the array creation / initialization constructs were not in Java 1.0, and (IIRC) were added in Java 1.1. But "why" is immaterial ... the restriction is there, and you have to live with it. I know how to work around it, but from time to time it would be simpler. By Considering all this you dont need to initialize with zero values for the array elements because by default all array elements are 0 for int array. I have a confusion about variable initialization in Java. As I understand, class variables get default. initialization while local variables are not initialized by default. However, if I create an array inside a. method using the new keyword, it does get initialized by default. All arrays in Java are initialized to the default value for the type. All java arrays implements Cloneable and Serializable. Java array initialization and instantiation together. Java Java JSRs Mobile Certification Databases Caching Books Engineering Languages Frameworks Products This Site Careers Other all forums. Array initialization. Initializing arrays in C is error-prone and tedious. Alternatively, you can use the shortcut syntax to create and initialize an array In Java, to initialize an array you can use the new keyword as well: int arrayName = new int[10]; As you can see, the array initialization is done, where [10] specifies that the array length is ten or array can contain ten elements. Информация взята v3.kz |
загрузка...
|