Results 1 to 5 of 5
Thread: Method to return values
- 11-10-2010, 07:44 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 9
- Rep Power
- 0
Method to return values
Hello. I wrote a method to return the values of the student name and the student age. How can I write a single method to return the values of a String and a int.
Thanks
Java Code:public class School { private String StudentName; private int StudentAge; public void setStudentName(String Name) { StudentName = Name; } public String getStudentName() { return StudentName; } public void setStudentAge(int Age) { StudentAge = Age; } public int getStudentAge() { return StudentAge; } }
- 11-10-2010, 07:54 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 11-10-2010, 08:16 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 9
- Rep Power
- 0
- 11-11-2010, 08:06 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Sure, you can make the ReturnValue class a nested class (the Student class will be the top level class) and make it public so the entire world can work with it:
kind regards,Java Code:public class Student { public static class ReturnValue { int ival; String sval; } // methods that return a ReturnValue go here ... } ... // somewhere else in your code: Student s= new Student(); Student.ReturnValue retval= s.someMethod(); // do something with retval.ival or retval.sval ...
Jos
- 11-11-2010, 09:27 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,479
- Rep Power
- 16
Similar Threads
-
Having XML readerclass return values, but which way is best?
By Kenjitsuka in forum New To JavaReplies: 0Last Post: 11-03-2010, 04:35 PM -
java method with multiple return values
By Ms.Ranjan in forum New To JavaReplies: 1Last Post: 06-18-2009, 06:08 PM -
Using functions that return values?
By Megapixelz in forum New To JavaReplies: 1Last Post: 04-30-2008, 04:07 AM -
how to return values from hashmap
By oregon in forum New To JavaReplies: 2Last Post: 08-01-2007, 04:56 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks