• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Master Exam Question - Incorrect answer?

 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Here is a question from Master Exam.
Quesion : What is the result ?
public class Test
{
public static void main(String[] args)
{
long [][] a1 ;
long []a2[];
a2 = new long[3][];
a1 = a2 ; // mark 1
System.out.println(a1[1][0]);
}
}
The answer says compilation error on line mark 1. But I am able to compile it and getting runtime exception as expected. Is there anything I am missing or the answer provided is incorrect?
Thanks in advance,
Prasad
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code gives NullPointerException and not the compiler error. As the array is 2-dimensional array & 2nd dimension is not defined,we cannot access the element a1[1][0].
reply
    Bookmark Topic Watch Topic
  • New Topic