• 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
  • Tim Cooke
  • Ron McLeod
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

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
 
What I don't understand is how they changed the earth's orbit to fit the metric calendar. Tiny ad:
Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders
https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing
reply
    Bookmark Topic Watch Topic
  • New Topic