java method return type :

java method return type :

i have one question regarding methods,,, if we create a method with return type as class name (public employee addemp(int,int))what should be its return type.....and if any know this pls explain with more example......
View Answers

September 10, 2010 at 12:49 AM

this is help u

example:1
class classasmethod
{
public static void classasmethod()
{
System.out.println("classasmethod method");
}
public static void main(String[] args)
{
System.out.println("main method");
classasmethod();
}
}
output is:
main method
classasmethod method



example:2

class classasmethod
{
public static int classasmethod()
{
System.out.println("classasmethod method");
return 10;
}
public static void main(String[] args)
{
System.out.println("main method");
int i=classasmethod();
System.out.println("i value is:"+i);
}
}
output is:
main method
classasmethod method
i values is:10


if u see above 2 example i use both return types(void and non-void).
here impotent one is be care full while calling class methods
if u call method with new key word it will constructor like below

new classasmethod();
it means create object,and calling the constructor implicitly .










Related Tutorials/Questions & Answers:

Ads