abhilashm86
August 22nd, 2009, 05:20 AM
can i have same method names in java?
i tried but there was errors, so i passes differnt datatypes, then it worked fine......
import java.util.Random;
public class samemehod {
void prt(String s) {
System.out.println(s);
}
int ret(int i) {
Random ran=new Random();
return i+ran.nextInt()%10;
}
double ret(double d) {
Random ran =new Random ();
return ran.nextDouble()%10+d;
}
public static void main(String[] args) {
samemehod s=new samemehod();
s.prt("int s="+s.ret(10));
s.prt("doube d="+s.ret(10.5));
}
}
as u see there is function
void prt(String s) {
System.out.println(s);
}
for this function if i pass like
s.prt(+10); or s.prt(10) it wont work
but it works if i write,
s.prt("int d="+10);
can i convert int to string before display or above method is correct?
how to keep same method name in above case, without passing any parameters?
i tried but there was errors, so i passes differnt datatypes, then it worked fine......
import java.util.Random;
public class samemehod {
void prt(String s) {
System.out.println(s);
}
int ret(int i) {
Random ran=new Random();
return i+ran.nextInt()%10;
}
double ret(double d) {
Random ran =new Random ();
return ran.nextDouble()%10+d;
}
public static void main(String[] args) {
samemehod s=new samemehod();
s.prt("int s="+s.ret(10));
s.prt("doube d="+s.ret(10.5));
}
}
as u see there is function
void prt(String s) {
System.out.println(s);
}
for this function if i pass like
s.prt(+10); or s.prt(10) it wont work
but it works if i write,
s.prt("int d="+10);
can i convert int to string before display or above method is correct?
how to keep same method name in above case, without passing any parameters?