+ 1
Why doesn't this code return what I want?
public class Program { int bark(int x, int y){ int z = x+y; return z; } public static void main(String[] args) { } } class Fu{ public static void main(String[] args){ Program myc = new Program(); myc.bark(2,3); } }
25 Answers
+ 4
this should work:
public class Program {
public static int bark(int x, int y) {
int z = x + y;
return z;
}
}
public class Foo {
public static void main(String[] args) {
Program prog = new Program();
int result = prog.bark(2,3);
System.out.println(result);
}
}
+ 2
Dekh Bhai ! program jab run krega to main method Dhundega yaha do main Method h to...Ek b run nahi hoga...To program class ka main method hata dena...! 2) return statement se screen pr print nahi hota...Value return hoti hai ...to Return ki hui value kahi store karna pdega...to Result Variable main Store Karlo ...jaise comment m program bana hai ...and File ka nam usi Class ka Nam ho ho jisme Main method hai...like Fu.java
+ 2
Thanks a lot
+ 2
yes
+ 2
ok
+ 2
yepp . no output
+ 2
got output
+ 1
your main method is empty...
+ 1
bro you are using two main function...! Only one main function can run at a time ...so remove main method of class program and you should use to know about return statement ...int result; then call result=myc.bark(2,3); then system.out.println(result);
+ 1
I am new in java ...
+ 1
please Detail #Shreyance_Gupta
+ 1
main method is the entry point of a java program. You have two of them.
+ 1
Java is both oop and procedural,and your first main function is empty .. so program will end there..
+ 1
ohh
+ 1
is it important to keep a method main?
+ 1
without main method program can't run!!!
+ 1
so, every program needs main function or method
+ 1
thanks for attending
+ 1
did you find the out put?
+ 1
try till you succeed