Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: call by value and call by reference

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default call by value and call by reference

    //Code=java//

    Here is the code of call by value and call by reference
    class test 
    {
    	void meth (int a,int b)
    	{
    		a*=2;
    		b/=2;
    	}
    }
    class callbyvalue 
    {
    	public static void main(String[] args)
    	{
    		test ob=new test();
    		int i=15,j=20;
    		System.out.println("i and j before call :" +i + " " +j);
    		ob.meth(i,j);
    		System.out.println("i and j after call : " + i + " " +j);
    	}
    }
     
    class test1 
    {
    int a,b;
    test1 (int i, int j)
    {
    	a=i;
    	b=j;
    }
    void meth(test1 o)
    {
    o.a*=2;
    o.b/=2;
    }
    }
    	class callbyref
    	{
    		public static void main (String args[])
    		{
    			test1 ob=new test1 (15,20);
    			System.out.println("ob.a and ob.b before call: " +ob.a +" " + ob.b);
    			ob.meth(ob);
    			System.out.println("ob.a and ob.b after call : "+ob.a +" "+ob.b);
    		}
    When i compile test.java file , It compiles and gives me a run time error main method not found in test ,please define the main method as public static void main(String args[])

    On the other hand , when i am compiling test1.java, it is also giving the same error.My question is main method is there in both the codes . So what do we mean by this error?

    Why is it so? Please help me resolve both as i have exam . Thanks

    //Code=Java
    Last edited by helloworld922; September 2nd, 2012 at 10:36 AM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: call by value and call by reference

    when i am compiling test 1.java, it is giving a run time error of could not load main class test 1.
    Not sure your question makes sense. It is not possible to have a space in a class name: test 1

    What don't you understand about the following error message:
    main method not found in test ,please define the main method as public static void main(String args[])
    What the java program is telling you seems very clear.

    Please Edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. How to call tablle
    By matsnys in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 16th, 2012, 11:53 AM
  2. How to call table?
    By matsnys in forum Member Introductions
    Replies: 1
    Last Post: August 15th, 2012, 01:49 PM
  3. How to call database???
    By mahoppe in forum JDBC & Databases
    Replies: 2
    Last Post: August 23rd, 2011, 08:31 PM
  4. Can't Call J2ee
    By DJB79 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: June 28th, 2011, 02:17 AM
  5. Call by Reference & Call by Value
    By Lokesh in forum Java Theory & Questions
    Replies: 1
    Last Post: February 21st, 2011, 01:19 PM