Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Wrapper Class

 
vijay Krishnan
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi it's me Again,

class objref
{
void print(Integer I)=============>Wrapper Class object for Integer class.
{
i++;
}
void print(int a[])
{
for(int ij=0;j<a.length;j++)
a[j]++;
}
public static void main(String[] args)
{
Integer i=new Integer(5);=====>object for Integer class;
new objref().print(i);
}
}


* Normally the value of arrayobject which we are passing to the method
is incremented and it is the type of callbyreference.
* But here i had created the object for WrapperClass Integer, but it wont be
like CallByReference model.
* My question is how the CallByReference is working for ArrayClasses and
Whynot to WapperClassess?

* Please Explain anyone with the suitable examples or Explanations.




Thanks & Regards,
Vijay
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vijay Krishnan:

* Normally the value of arrayobject which we are passing to the method
is incremented and it is the type of callbyreference.



No it isn't.

Originally posted by vijay Krishnan:

* But here i had created the object for WrapperClass Integer, but it wont be
like CallByReference model.



Of course not, Java doesn't have pass by reference/call by reference. You mistakenly assumed that's what was happening with the array because you misunderstand what a reference in Java is.

Originally posted by vijay Krishnan:

* My question is how the CallByReference is working for ArrayClasses and
Whynot to WapperClassess?
* Please Explain anyone with the suitable examples or Explanations.



There is only one passing mechanism in Java and it is pass by value. You should read this:

http://www.javaranch.com/campfire/StoryCups.jsp

Hopefully it will help you. I would explain further, but chances are it'd muddy the waters and that page is pretty good at explaining it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic