Click here to Skip to main content
15,923,218 members

Comments by Member 13771743 (Top 4 by date)

Member 13771743 12-Apr-18 12:31pm View    
good point my bad, thank you for that even though what i really want to is how to access one class variables through another as i have shown in the above example
do i need to creat an object of that in order to use it inside another class

i found out by making it "public static" within the class (not inside a method) makes it able to use it in any class by String nm1=Class.Attribute() is it correct to make it public static just so i can use it in any class? if now how can i access a variable in one class from another tht has a value assigned to it
Member 13771743 12-Apr-18 10:14am View    
Thank you alot but i wasnt worried about finding the age i just wanted to know how to use variables from one class to another what is the correct way of doing so how bout setters and getters what role do they play
Member 13771743 10-Apr-18 12:22pm View    
@jocen i am aware of the usage of double points2=character.getHitpoints();
what i am asking is in the above one lets say i am prompting the user to enter 10 values for "10 different skills" so here i can use a for-loop or i can use 10 variables or i can store all of these inputs in an array. Lets say i did this in the character class as i have mentioned above. What if i want to use them inside another class ? is it correct for me to define those 10 variables (assuming i am using 10 variables instead of an array and what not) static so i can access them inside the other class ? Or assume i am using the array to store them is it correct for me to define the array out side an method(basically right after defining the class exactly like v done in the example) so i can use it inside another class ? if not how should i go about doing so ? is setters and gettes an option ? lets say i wanted to get this array values printed but those are inside a method in another class? is it correct for me to define them like iv done ? if not please explain how i should do so by using the example i have provided.
private static int [] arr={1,2,3}

Thnk you
Member 13771743 10-Apr-18 10:49am View    
@jocen i am aware of the usage of double points2=character.getHitpoints();
what i am asking is in the above one lets say i am prompting the user to enter 10 values for "10 different skills" so here i can use a for-loop or i can use 10 variables or i can store all of these inputs in an array. Lets say i did this in the character class as i have mentioned above. What if i want to use them inside another class ? is it correct for me to define those 10 variables (assuming i am using 10 variables instead of an array and what not) static so i can access them inside the other class ? Or assume i am using the array to store them is it correct for me to define the array out side an method(basically right after defining the class exactly like v done in the example) so i can use it inside another class ? if not how should i go about doing so ? is setters and gettes an option ? lets say i wanted to get this array values printed but those are inside a method in another class? is it correct for me to define them like iv done ? if not please explain how i should do so by using the example i have provided.
private static int [] arr={1,2,3}

Thnk you