Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Argument Passing

Have Programming Question? Ask it here!
 
 
 


Mukesh
Argument Passing
1 Answer(s)      2 years and 3 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.


Advertisement
View Answers

April 18, 2012 at 4:17 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);


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
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
Passing variable
Passing variable  How to pass variable to HTTP object in HTMl or PHP
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
Command line argument in java
Command line argument in java. In this section we are going to discuss about command line argument in java. Command line argument allow a user to pass... user to pass any number of  argument to the command line. When running
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
Java Generic program with command line argument
Java Generic program with command line argument  Implement Generic to perform arithmetic evaluation using command line argument by using Java
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
What is the first argument of the String array in main() method?
What is the first argument of the String array in main() method?  Hi, What is the first argument of the String array in main() method? Thanks... array in very efficient manner. For details on What is the first argument
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 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
No Argument Constructor Example
No Argument Constructor Example   ... class consists No-Argument Constructor or not ?. Here is an example... newInstance() method to create a new object without any argument. Invoking
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
Passing Parameter - JSP-Servlet
Passing Parameter  I would like to ask how to pass a parameter from javascript section into the jsp section.It will be something like...; answer<%; <---I'm stuck here passing the var
passing value of radio button
passing value of radio button  hi,i have 3 jframe built using the GUi editor in net beans 6.9. i have two radio button in the first jframe.i have to get the selected item appear on the 3rd frame after passing through the second
Passing Arguments. - Java Beginners
Passing Arguments.  Hi, im new in doing this passing arguments and calling methods. Can you please see that y im not getting the answer as the question says to do. Thanks Question:Write a method that is passed two arguments
Passing Command Line Arguments
Passing Command Line Arguments     ... pass values on command line argument . We are taking a sequence... string at run time on command line argument then the message  "
Passing Parameters - JSP-Servlet
Passing Parameters  Hi I have to pass parameter like such scenario. Please help me on emergent bases. I will be grateful. First Page First Name /**SECOND PAGER upto this page I passed the parameter through query
passing parameters - JSP-Servlet
passing parameters  hi this is my jsp page Reserved By: Conference Hall No: Select Hall Numbers
Passing Parameter - JSP-Servlet
Passing Parameter  Hi, it'me again. Below is the set of code that I get from your solution entitled droplist that read from database. It do read from database but in the textbox of the webpage, i need it to show something
passing values - JSP-Servlet
passing values  hi this is my jsp page Reserved By: Conference Hall No: Select Hall Numbers Time Slot: Select Time Slot Date
passing value from javascript popup
passing value from javascript popup  How to take user input and pass that input value using popup in Javascript
Passing a parameter using URL string
Passing a parameter using URL string  How to pass a parameter using the URL string in a JSF application
passing parameter from html to applet
passing parameter from html to applet  how to pass the following from HTML to applet in Java code - font size,font style,font size?give me suitable code
JavaScript array passing
JavaScript array passing     ... an example of passing array to the methods or functions. When any array object... object as argument and adds one element "Track" at the index "2
Example to show Argument Exception in java
Example to show Argument Exception in java  ... from Argument exception in java .Exceptions are the condition  in Java... describes  how to handle Argument exceptions appropriately in your programs
passing .properties file as a parameter to another function
passing .properties file as a parameter to another function  passing .properties file as a parameter to another function in an jsp file
passing .properties file as a parameter to another function
passing .properties file as a parameter to another function  passing .properties file as a parameter to another function in an jsp file
passing .properties file as a parameter to another function
passing .properties file as a parameter to another function  passing .properties file as a parameter to another function in an jsp file
passing .properties file as a parameter to another function
passing .properties file as a parameter to another function  passing .properties file as a parameter to another function in an jsp file
Passing parameters in JSP using forward.
Passing parameters in JSP using forward.  If a page is forwarded to another page using jsp:forward, is it necessary that the page should be already created? Or will the compiler create one?   Hi, it necessary
passing data between the jsp pages ?
passing data between the jsp pages ?  i developed a project on student marks system.in this project their is one html page which asks user to enter the roll number and when we press submit button on that page it moves a jsp page
XML clonning with java and passing arguments
XML clonning with java and passing arguments  Hi, I have a XML file as follows. My requirements are as below. 1. Clone the whole xml file. 2. Iterate depending on the number provided. Say 1 means only one set with arugments1
Passing a java property to a javascript variable
Passing a java property to a javascript variable  i want to assign a java property to a js variable: action class: collegename have a property in action class which having its getter/setter method. JSP code: <%@ taglib
java util date - Time Zone throwing illegal argument exception
java util date - Time Zone throwing illegal argument exception  Sample Code String timestamp1 = "Wed Mar 02 00:00:54 PST 2011"; Date d = new Date... is throwing an Illegal Argument Exception Why is the second SOP always throwing
Passing td cell id to servlet
Passing td cell id to servlet  Hi all, I am new to JSP/Servlet .Please help. I need to send the table cell index in servlet using javascript and should be able to make a cell index to have a text - "X" / "0"only once. Here
 

 

 

DMCA.com