This week's giveaway is in the Beginning Java forum.
We're giving away four copies of Bad Programming Practices 101 (e-book) and have Karl Beecher on-line!
See this thread for details.
Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Query:Data Type Conversions :Array to Object  RSS feed

 
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
In java ,
We can convert(automatically convertd) array reference to object of Object class
ie
Object o;
int arr[]={1,2,3};

o=arr; //this line is legal

Now ,o points to same memory location ,to which arr was referencing.
Can we access to the data (list to value or array data) through Object o.
thnx
 
Ranch Hand
Posts: 2410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, o can only access the methods of Object.

You will have to cast o to an array reference before you can access the elements with the array access operator.
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lucky,

Although you can do the following:





cmbhatt
 
Roses are red, violets are blue. Some poems rhyme and some don't. And some poems are a tiny ad.
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!