You are here:

Java/Return Type in Java

Advertisement


Question
Dear Sir,
I want to know that how can i define my return type?
like
  public Myreturntype fun1()
   {
       return Myvalue;
   }
As i have already used predefined Return type like String,int But I want to know How can We make My return type?

Answer
Any class is a valid return type.

E.g.

public class Stuff
{
  public String stuffStr;
  public int stuffInt;
}

public Stuff fun1()
{
  Stuff stuff = new Stuff();
  stuff.stuffStr = "Hello";
  stuff.stuffInt = 42;
  return stuff;
}

Java

All Answers


Answers by Expert:


Ask Experts

Volunteer


Artemus Harper

Expertise

I have a Masters in computer science. I can answer questions on core J2SE, swing and graphics. Please no questions about JSP or J2ME.

Experience

I have experience in Core Java, good background in Java swing/gui, some experience with JNI, Java reflection. Some experience in bio-informatics. Basics in c++ and c#

Organizations
Washington State University

Education/Credentials
MS in Computer Science from Washington State University and a BS in Mathematics and Computer Science from Central Washington University.

©2016 About.com. All rights reserved.