English

Given: int n = 0; int ar[] = new int [n]; ar[0] =25; System.out.print(" ar0] =“ + ar[0]); The code will generate ______.

Advertisements
Advertisements

Question

Given:

int n = 0;
int ar[] = new int [n];
ar[0] =25;
System.out.print(" ar0] =“ + ar[0]);

The code will generate ______.

Options

  • no error

  • logical error

  • syntax error

  • runtime error

MCQ
Fill in the Blanks
Advertisements

Solution

The code will generate runtime error.

Explanation:

The array is created with size 0, so it contains no elements. Attempting to access ar[0] results in an ArrayIndexOutOfBoundsException at runtime because index 0 does not exist.

shaalaa.com
  Is there an error in this question or solution?
Chapter 7: Arrays - One Dimension - Exercises [Page 172]

APPEARS IN

Rupa Pandit Computer Applications [English] Class 10 ICSE
Chapter 7 Arrays - One Dimension
Exercises | Q 1. (v) | Page 172
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×