Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners java method return type :
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


gokulcrp
java method return type :
1 Answer(s)      4 years and a month ago
Posted in : Java Beginners


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......

Advertisement
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:
Advertisements
 

 

 

DMCA.com