Java Programming - Language Fundamentals - Discussion
Discussion Forum : Language Fundamentals - General Questions (Q.No. 8)
8.
Which one of the following will declare an array and initialize it with five numbers?
Answer: Option
Explanation:
Option B is the legal way to declare and initialize an array with five elements.
Option A is wrong because it shows an example of instantiating a class named Array, passing the integer value 5 to the object's constructor. If you don't see the brackets, you can be certain there is no actual array object! In other words, an Array object (instance of class Array) is not the same as an array object.
Option C is wrong because it shows a legal array declaration, but with no initialization.
Option D is wrong (and will not compile) because it declares an array with a size. Arrays must never be given a size when declared.
Discussion:
25 comments Page 1 of 3.
Vivek Singh said:
5 years ago
@All.
C is incorrect.
Declare an array and initialize it with five numbers.
declare an array and it should be initialized with 5 numbers..
Here we just saying size 5 i.e int a [] = new int[5];
but we haven't initialized or assign a value.
Hence, option C is wrong.
C is incorrect.
Declare an array and initialize it with five numbers.
declare an array and it should be initialized with 5 numbers..
Here we just saying size 5 i.e int a [] = new int[5];
but we haven't initialized or assign a value.
Hence, option C is wrong.
(1)
Sudheer said:
7 years ago
New operator creates object and initializes variables with default values.
As, it is initializing with default values we can consider option C also as an answer.
As, it is initializing with default values we can consider option C also as an answer.
(1)
Ravi said:
8 years ago
My point of view option :C also correct because by default it can initialize with 5 numbers that is all five numbers are 0s.
(1)
Jagdish singh said:
8 years ago
In c option, we declare an array with size 5 it means we can store 5 elements in this but according to the question, we need to initialize the value at the time of array declaration.
(1)
Saki said:
8 years ago
Why option C is false? I don't know this. It's not true? Please explain.
Sagar singh said:
9 years ago
Instantiate is to create an instant of any class or create an instance of the class.
eg : Class1 obj = new Class1(); // here we instantiate the the class by creating its object.
Initialize means to involve value in any data member or integer.
eg : Array1[] new = {1,2,3,4,5}; // here we intialieze the array with 5 new integers.
eg : Class1 obj = new Class1(); // here we instantiate the the class by creating its object.
Initialize means to involve value in any data member or integer.
eg : Array1[] new = {1,2,3,4,5}; // here we intialieze the array with 5 new integers.
ShankPossible said:
9 years ago
In short option B and C both are correct.
Option C would have become incorrect if we were talking about the local variables.
Option C would have become incorrect if we were talking about the local variables.
Cutie said:
9 years ago
Difference b/w instantiate and initialize ?
Anyone ?
Anyone ?
(1)
Karthick said:
9 years ago
Can anybody tell me, what is the difference between instantiate and initialize?
(1)
Harsh said:
1 decade ago
Awesome. Option C describes only array declaration not initialization.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers