call by value and call by reference
//Code=java//
Here is the code of call by value and call by reference
Code java:
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
Re: call by value and call by reference
Quote:
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:
Quote:
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.