• 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

Array

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello,
Why does the following code is showing an error

public class sum
{
public static void main(String[]args)
{

byte[] array1,array2[];
array2=array1;
}
}

 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi fraternity,
<code>byte[] array1, array2[]</code> produces <code>array1[], array2[][]</code>. These are not equivalent. <code>array1</code> has one dimension, <code>array2</code> has two dimensions.
You can only assign arrays of the same 'type'. Arrays have a class type that is determined when they are created. See JLS §10.8
Try the following:

Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
lawson,
if you want to declare array2 as one dimensional array then
byte[] array1,array2;
for assigning the array1 to array2
you should construct array1
array1=new byte[5];
array2=array1
jeena jose
 
reply
    Bookmark Topic Watch Topic
  • New Topic