‹ Back to the paper
Question 2(e)
2 marks
Computer ScienceISC 2020 Computer Science Paper 1Short answerObjects
Answer the following in short.
What is the significance of the keyword ‘new’ in Java? Mention the areas where it is used.
Answer
Answer
The keyword 'new' is an operator that dynamically allocates memory at run time (from the heap) for an object or an array, calls the constructor to initialise it, and returns a reference to the newly created memory.
Areas where it is used:
1. To create objects of a class, e.g. $Student\ s = new\ Student();$
2. To create arrays, e.g. $int\ a[] = new\ int[10];$
3. To create objects of library classes, e.g. $Scanner\ sc = new\ Scanner(System.in);$
4. To create nodes of dynamic data structures such as linked lists and trees, e.g. $Node\ t = new\ Node();$