• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

array assignments

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
byte [] b1, b2[];
byte b3 [][];

b2 is a 2 dimensional array....so can't b3 be assigned to b2?
b2 = b3;

Thanks,
Neelima
 
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Neelima,
Try this and let me know what you think.
 
Neelima Chandran
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
looks like a valid assignment....sorry I don't have java running on my current system to check that out. pls help!
 
Jay Pawar
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Neelima,
If you write the code as shown below


You will get compile time error at LINE X saying b3 is not initialized. So you need to specify constant values to the array b3 or either allocate memory using new operator.
b3 = new byte[1][1];

and as far as the original question is concerned yes both b2 and b3 are two dimensional arrays.

A word of advice: If you are planning to give the certification , download java sdk from sun web site and try out the code. You need to have lot of coding practice, reading books is not just sufficient.


Good Luck !!!
 
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ofcourse Neelima , You can assign if the arrays are not uninitilized.



And the above code compiles fine.

Hope that helps
[ October 16, 2005: Message edited by: Sandeep Chhabra ]
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and if al your arrays were instance variables (members of a class) it would no problem to assign b3 to b2, because they both are referring to null.

but if they are local variables, they must be initialized before use (so you have to initialize b3 before you can assign it to b2)
 
We can fix it! We just need some baling wire, some WD-40, a bit of duct tape and this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic