Home Answers Viewqa Java-Beginners Passing Argument in Java

 
 


Mukesh
Passing Argument in Java
1 Answer(s)      a year and a month 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.

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);









Related Pages:
Java argument passing
Java argument passing  How many ways can an argument be passed to a subroutine and explain them
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
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
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... path=C:\Program Files\Java\jdk1.6.0_11\bin C:\commandLineArgument>javac
object as argument
object as argument  what happens when we pass a object into a method???if java is pass by value how does this makes a difference.....pllzzz give me more clarification on why we pass objects in a margument
Passing Command Line Arguments
\completed>java ArgumentPassingExample rajesh kumar rahul The values enter at argument... Passing Command Line Arguments     ... pass values on command line argument . We are taking a sequence
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.... Suppose we are running java application, then class name followed by argument
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
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 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
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.... This article gives your a very easy java program which illustrates about the string
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 parameters - JSP-Servlet
passing parameters  hi this is my jsp page Reserved... No: this is my java page for insertion package CHB; import
passing values - JSP-Servlet
passing values  hi this is my jsp page Reserved By: Conference Hall... No: this is my java page for insertion package CHB; import
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.../javascript"); %> var collegename = ''; Java Script code: alert("collegename
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
java util date - Time Zone throwing illegal argument exception
java util date - Time Zone throwing illegal argument exception  ...()); The date object is not getting created for IST time zone. Java is throwing an Illegal Argument Exception Why is the second SOP always throwing
Applet - Passing Parameter in Java Applet
Applet - Passing Parameter in Java Applet   ... case applet should display "Welcome in Passing parameter in java applet...;Passing Parameter in Java Applet</TITLE> </HEAD> <
Concatenate pdf files using command argument
Concatenate pdf files using command argument   ... pdf files into a destination pdf files through java program. The all data... destination file name. Read the file  from command argument and find
JSP:Passing query as parameter - Java Beginners
JSP:Passing query as parameter  Hi Friends, I have a real tough time in finding the solution of a problem. I am here to find a real solution of my problem. Please help me solve this problem. My Problem is: I have 3 query
JSP:Passing query as parameter - Java Beginners
JSP:Passing query as parameter  Hi Friends, I have a real tough time in finding the solution of a problem. I am here to find a real solution of my problem. Please help me solve this problem. My Problem is: I have 3 query
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
Passing Various Data Types into Cells
passing various data types into cells   ... data types into the cells and rows in the excel sheet using java .You can.... The argument "value" (short type) is the number for which we are going
Passing values from child window to parent window.
Passing values from child window to parent window.  http://www.roseindia.net/java/pass-value-example/pass-value-child-to-parent.shtml I have gone thru the link but my requirement is checkboxes.can u please explain
Passing parameter over Form to BackingBean - Java Server Faces Questions
Passing parameter over Form to BackingBean  Dear User, i have problems concerning passing parametes from form to my backing bean. I have... here, my Bean Code. This is the form
Passing values from child window to parent window.
Passing values from child window to parent window.  Hai, I'm having a requirement ,in that when i open a (pop-up)child window from a parent window... the following link: http://www.roseindia.net/java/pass-value-example/pass-value
passing value fron script to scriplet - JSP-Servlet
passing value fron script to scriplet  how to pass value from Java... from the client (javaScript) to the server (java), you have to submit a form... (java), you have to submit a form, or use a the name/value query string. your
Passing java variables from JSP to Servlet - return null values
Passing java variables from JSP to Servlet - return null values  I... the java code of my JSP. In JSP page I did, String msg="hello... to get java variables from JSP tp servlet? If there is some error in my code
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 values in ComboBox from XML file
Passing values in ComboBox from XML file In this tutorial we are going.... This tutorial is only geared towards showing how to construct a Java object... will define a factory API which allows our application to obtain a Java XML 
Passing variable
Passing variable  How to pass variable to HTTP object in HTMl or PHP
passing parameter from Java code to CSS file - Design concepts & design patterns
passing parameter from Java code to CSS file  hi, i have to pass a string variable from by java code to a CSS file so that i can use that variable in my CSS file. Plz help me as soon as possible
passing values between jsp file through hyperlink in div tag
passing values between jsp file through hyperlink in div tag  <p>hi please help me to solve this. i have searchproj.jsp and updateproj.jsp....;%@ page language="java"%&gt; &lt;%@ page import ="java.sql.*"%&
Need to expand tree by passing Id thr URL. (not by clicking manually) - Java Server Faces Questions
Need to expand tree by passing Id thr URL. (not by clicking manually)  Sub: Need to expand tree by passing Id thr URL. Hi, Here i have...=tree&albumIds=1001,1002,1005,1008,1009,1010&client=0" I m passing album Ids
Need to expand tree by passing Id thr URL. - Java Server Faces Questions
Need to expand tree by passing Id thr URL.  Hi, Here i have...=tree&albumIds=1001,1002,1005,1008,1009,1010&client=0" I m passing album Ids... by passing the clientId from Url. How can I do it. Plz help asap
passing xml created using DocumentBuilderFactory as input to oracle stored procedure using java JDBC
passing xml created using DocumentBuilderFactory as input to oracle stored procedure using java JDBC  I want to send the xml as input parameter... is my java code... import java.io.; import javax.xml.parsers.; import
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 - Java Beginners
java  Hello deepak u said that java does not support call by reference.But java support passing of object as an argument.Which means java support... then what it is called then passing an object as an argument
Passing Arrays In Jsp Methods
Passing Arrays In Jsp Methods   ... arrays are most commonly used arrays in java. JSP is a technology which enables us... will become dynamic.  In this example of  jsp for passing arrays in Jsp
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
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.