Results 1 to 5 of 5
  1. #1
    ii88xix88ii is offline Member
    Join Date
    Jan 2013
    Location
    Philippines
    Posts
    14
    Rep Power
    0

    Default functions and variables

    how do you get a value from a function and assigning that value to a variable?

  2. #2
    ii88xix88ii is offline Member
    Join Date
    Jan 2013
    Location
    Philippines
    Posts
    14
    Rep Power
    0

    Default Re: functions and variables

    ex:

    class class_name{

    int counter;

    public int getCounter(){
    return counter;
    }
    public void setCounter(int count){
    counter = count;
    }
    |}

    is there any way wherein we can get the value of counter then assign it to a different variable?

  3. #3
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,026
    Rep Power
    6

    Default Re: functions and variables

    First, please put you code between code tags [code][/code] as shown.


    Java Code:
    class Class_name{
     
        int counter;
     
        public int getCounter(){
            return counter;
        }
        public void setCounter(int count){
            counter = count;
        }
    }
    
    /*
     To use the above class to assign a value to another int, you can do something like
    the following from another class.  However, there may be visibility issues depending on how
    you package your class, etc.
    */
        Class_name cn = new Class_name();
        cn.setCounter(10);
        int val = cn.getCounter();
    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    ii88xix88ii is offline Member
    Join Date
    Jan 2013
    Location
    Philippines
    Posts
    14
    Rep Power
    0

    Default Re: functions and variables

    thanks Jim..

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: functions and variables

    For the record, Java doesn't have functions. Java has methods.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Functions Graph
    By wally in forum AWT / Swing
    Replies: 6
    Last Post: 11-14-2010, 12:01 AM
  2. JSP Functions
    By sysout in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 11-07-2009, 05:10 AM
  3. What are Instance variables and static variables?
    By sandeshforu in forum New To Java
    Replies: 3
    Last Post: 09-09-2009, 06:48 PM
  4. 2 functions
    By baze7 in forum New To Java
    Replies: 3
    Last Post: 08-14-2009, 05:41 AM
  5. Functions in jsp
    By samson in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 03-25-2009, 11:04 PM

Posting Permissions

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