Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19
Object Oriented question. - Page 2
Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 29

Thread: Object Oriented question.

  1. #11
    Guest

    Re: Object Oriented question.

    To my knowledge, you can't. At least not in one method. This works the same in C and C++, but the bigger question is to what purpose do you want to return two values at the same time?

  2. #12

    Re: Object Oriented question.

    I don't know any Java, but would it be possible to put a and b into an array, then return the array?

  3. #13
    Guest

    Re: Object Oriented question.

    Code:
    class retarr {
    
    // one of the most important features of Java is its access modifiers. 
    // The 'static' modifier differs from that of C and C++ 
    // in that it tells the compiler that this method cannot be instantiated, 
    // but rather is 'static' to this application.
      public static int[] retInt(int a, int b) { 
       int[] intArr = new int[2]; 
       // there are many ways to create arrays in Java, this is one of them.
       intArr[0] = a;
       intArr[1] = b;
       
       return intArr;
      }
    
    // this is your garden variety main method
      public static void main(String args[]) {
       int[] intArr2 = retInt(3,6);
       for (int i=0; i<intArr2.length; i++)
         System.out.println(intArr2[i]);
      }
    }

  4. #14
    Guest

    Re: Object Oriented question.

    As such, objects in C++ can't return stuff, that's functionally which lies in the implementation of the member functions. I assume that it's the same in that coffee language.

  5. #15
    Mentor
    Join Date
    Jun 2001
    Posts
    1,672

    Re: Object Oriented question.

    An array won't do it, since I'm trying to return different variables, a float and an String.

    Is there another way of passing values from a method to the caller? The method I'm working on generates an int and a String that needs to be passed on to the caller.


  6. #16

    Re: Object Oriented question.

    Why dont you create a and b as global variable to expand its scoope?

    public class test {
    float a;
    int b;
    public float test() {
    a = 1.1;
    b = 1;
    }

    This way you may have the values available to all the methods, but i may be wrong. ;D

  7. #17
    Mentor
    Join Date
    Jun 2001
    Posts
    1,672

    Re: Object Oriented question.

    Why dont you create a and b as global variable to expand its scoope?

    public class test {
    * float a;
    * int b;
    * public float test() {
    * * * a = 1.1;
    * * * b = 1;
    }

    This way you may have the values available to all the methods, but i may be wrong. ;D
    Yes, I've thought about using global variables, but I'm trying to avoid that as mush as I can. If to program gets big, it's hard to keep track of them (done that in Perl, became a nightmare).

  8. #18

    Re: Object Oriented question.

    What kind of values are you going to return?, are they string,int,etc.? some example of the data.
    Because the array solution can be used if we know some of this answers.

  9. #19
    Mentor
    Join Date
    Jun 2001
    Posts
    1,672

    Re: Object Oriented question.

    What kind of values are you going to return?, are they string,int,etc.? some example of the data.
    Because the array solution can be used if we know some of this answers.
    What I'm trying to do is to have a method that does a query in a database and return the number of rows (int) that matched the query. If something goes wrong with the query (couldn't connect to the database, etc.), I want the method to return a String with an error message, otherwise an empty string.

  10. #20

    Re: Object Oriented question.

    Ok this i what i'll do.
    1 the function will only return 1 value at time.
    2 the value is is a number can be returned as a string and the can be casted.
    3 If the value is an error message its going to be a string.

    So the function for me can return a string.

    public class test {

    public String test() {
    .
    .
    .
    return a;
    }

    Remember If you are returning Records number dont use int, use long.

    In java to convert a string to Long use: parseLong. if the value cant be parsed (error message string) it throws a NumberFormatException Exception.
    HtH

Similar Threads

  1. object file not supporting kernel version
    By misbah_khan in forum Linux - General Topics
    Replies: 1
    Last Post: 11-27-2006, 07:02 AM
  2. Testing through Shared Object File of Code
    By honey bee in forum Linux - Software, Applications & Programming
    Replies: 1
    Last Post: 07-27-2006, 12:19 PM
  3. libXmu.so: cannot open shared object file: Too many levels of symbolic links
    By shupi in forum Linux - Software, Applications & Programming
    Replies: 0
    Last Post: 07-04-2006, 05:18 AM
  4. libXmu.so: cannot open shared object file
    By shupi in forum Linux - General Topics
    Replies: 0
    Last Post: 07-02-2006, 09:49 AM
  5. Possible to get different object files from the same source code & toolchain?
    By josaiah in forum Linux - Software, Applications & Programming
    Replies: 3
    Last Post: 10-17-2002, 02:24 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •