Argument Passing

Ads

 
 

Share on Google+Share on Google+

Mukesh
Argument Passing
1 Answer(s)      5 years and 4 months ago
Posted in : Java Beginners

hi this is my code

class Test {

    void meth(int i, int j) {
        i *= 2;
        j /= 2;
        System.out.println("a=" +i);
        System.out.println("b=" +j);
    }
}
public class CallByValue1 {
  public static void main(String args[]) {
        Test ob = new Test();
        int a = 15, b = 20;
        System.out.println("a and b before call: "
                + a + " " + b);
        ob.meth(a, b);
        System.out.println("a and b after call: "
                + a + " " + b);
    }
}

why these lines

            System.out.println("a=" +i);
            System.out.println("b=" +j);

print a=30 & b=10 As changes made to the parameter of the subroutine have no effect on the argument plz clear my doubts soon.

Ads
View Answers

April 18, 2012 at 4:10 PM


In the method you have multiplied the number by 2 and in the main method you have declared two numbers a is 15 and b is 20.So when you have called the method meth() of Test class, the method takes the arguments 15 and 20 as a result it multiply the value of a i.e 15 by 2 and divide the value of b 20 by 2 to produce the output 30 and 10 respectively. This method is of void type and so does not have any return type. So the following code displays the values 15 and 20.

System.out.println("a and b after call: "+ a + " " + b);

Ads









Related Tutorials/Questions & Answers:
Argument Passing
Passing Argument in Java  hi this is my code class Test { void meth(int i, int j) { i *= 2; j /= 2... to the parameter of the subroutine have no effect on the argument plz clear my
Argument Passing
Argument Passing  hi this is my code class Test { void meth(int i, int j) { i *= 2; j /= 2; System.out.println... no effect on the argument plz clear my doubts soon.   In the method you
Advertisements
Argument Passing
Argument Passing  hi this is my code class Test { void meth(int i, int j) { i *= 2; j /= 2; System.out.println... no effect on the argument plz clear my doubts soon.   In the method you
Argument Passing
Argument Passing  hi this is my code class Test { void meth(int i, int j) { i *= 2; j /= 2; System.out.println... no effect on the argument plz clear my doubts soon.   In the method you
Argument Passing
Argument Passing  hi this is my code class Test { void meth(int i, int j) { i *= 2; j /= 2; System.out.println... no effect on the argument plz clear my doubts soon.   In the method you
Argument Passing
Argument Passing  hi this is my code class Test { void meth(int i, int j) { i *= 2; j /= 2; System.out.println... no effect on the argument plz clear my doubts soon.   In the method you
Argument Passing
Argument Passing  hi this is my code class Test { void meth(int i, int j) { i *= 2; j /= 2; System.out.println... no effect on the argument plz clear my doubts soon.   In the method you
Java argument passing
Java argument passing  How many ways can an argument be passed to a subroutine and explain them
Passing argument at command line using Core Java
How to pass Command Line Argument using Core Java Description : This example demonstrate how value accepted from the command line. All argument need to placed at the command line at the time of executing your program.  class
Passing variable
Passing variable  How to pass variable to HTTP object in HTMl or PHP
ArrayList as an argument to another class
ArrayList as an argument to another class  how do you pass arraylists as arguments to another class, and how does the method/class accept this arraylist for use
Version of com.obdobion>argument dependency
List of Version of com.obdobion>argument dependency
Passing array element
Passing array element  What about passing an element of an array? If I have array of objects and pass functionA(arr[2]); Then functionA() will get arr[2] as a value type or a reference type
Java parameter passing
Java parameter passing  What type of parameter passing does Java support
Objective C Message Passing
Objective C Message Passing  What exactly a message passing means in Objective C? and how can i pass a message to a method
Maven Dependency argument >> 4.3.5
You should include the dependency code given in this page to add Maven Dependency of com.obdobion >> argument version4.3.5 in your project
Maven Dependency argument >> 3.0.1
You should include the dependency code given in this page to add Maven Dependency of com.obdobion >> argument version3.0.1 in your project
Maven Dependency argument >> 4.3.8
You should include the dependency code given in this page to add Maven Dependency of com.obdobion >> argument version4.3.8 in your project
Maven Dependency argument >> 4.1.2
You should include the dependency code given in this page to add Maven Dependency of com.obdobion >> argument version4.1.2 in your project
Maven Dependency argument >> 3.0.2
You should include the dependency code given in this page to add Maven Dependency of com.obdobion >> argument version3.0.2 in your project
Maven Dependency argument >> 4.3.4
You should include the dependency code given in this page to add Maven Dependency of com.obdobion >> argument version4.3.4 in your project
Maven Dependency argument >> 4.1.0
You should include the dependency code given in this page to add Maven Dependency of com.obdobion >> argument version4.1.0 in your project
Maven Dependency argument >> 4.0.4
You should include the dependency code given in this page to add Maven Dependency of com.obdobion >> argument version4.0.4 in your project
What is command line argument in Java
What is command line argument in Java  What is command line argument in Java and how one can use it to create a program in Java? Can you post any example of command line argument program in Java?? It will be really helpful
passing values on button click
passing values on button click  Please help me to solve this issue.I want to pass a value assigned to button to another view upon button click in xcode
Reference passing in java
Reference passing in java  plz tell me wat d meaning of refernce in java? for example : Class M(){ N n; } Class N(){ } wats dis meaning
passing values in hyperlink
passing values in hyperlink  Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
passing values in hyperlink
passing values in hyperlink  Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
passing values in hyperlink
passing values in hyperlink  Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
passing values in hyperlink
passing values in hyperlink  Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
passing values in hyperlink
passing values in hyperlink  Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance