![]() |
Need help passing variable to another class
I'm trying to call the variable r from another class, but I'm having trouble making it.
Code:
public class Circle {Code:
import java.util.Scanner;Basically I want the user input (r) to go to the other class so I can get different measurements from it and then return those values back to the original class using System.out.print. Thanks. |
Since the datatype is primitive, you cannot pass it around and change it. Only objects work via object pointer references in java (and only with mutable object types).
You can pass it to the circle's setRadius method to set the value in the class instance of Circle. Changing it within circle will not modify it in the main, for that you would need to retrieve the value again from the getRadius method (or whatever you are fetching). |
| All times are GMT +1. The time now is 08:50 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.