Argument Passing in JAVA


AutomationChinnu

There are two ways of passing arguments:

  1. Call-by-Value   – The value of the argument is passed to the parameters (values of the primitive data type are passed)
  2. Call-by-Reference  – The reference of the argument is passed to the parameters (objects are passed)
Lets implement the call-by-value on Eclipse IDE:
1. Launch Eclipse IDE, Create a new Java Project ‘Project 005’, Create a Test class without main( ) method as shown below:
2. Create Test( ) constructor with two int type parameters as shown below and save:
3. Create another class ‘CallByValue’ with main( ) method as shown below
4. Declaring two integer variables ‘i’ and  ‘j’ and initialize them with integer values as shown below:
5. Print the values of ‘i’ and ‘j’ before calling Test( ) constructor in Test Class as shown below:
6. Create an object ‘object1’ and pass the values of i,j to the Test( ) constructor in…

View original post 436 more words

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s