Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Ability to "share" ints or doubles or strings with multiple classes.

Mighty Hackfourm users!I need your help!

The STORY:
I was watching a You-tube tut about Java and I decided to make a mini Facebook Application.What it does is that it just simply ask you for your First Name And Last Name.
The Problem:
I cannot print an int if It was in another class.I have tried to use the following code to help,but still it does not work.(Perhaps the code won't help at all?)
PHP Code

<?php 
        FacebookFirstName FirstNameObject 
= new FacebookFirstName ();
        
FirstNameObject.FirstName(FacebookFirstName1); 
HOW TO HELP:
I was wondering if you guys have any idea how to share ints or doubles with multiple classes?Say I imported Scanner and I were to make it so that two ints add together,but in the other class it would print up the combined int?

CODE:
This is my entrie code if you need it to help me.
FacebookMain.java
Spoiler (Click to View)
FacebookFirstName.java
Spoiler (Click to View)
FacebookSecondName.java
Spoiler (Click to View)
If you were to help me you will get an invisible cookie for helping me :)
First, your naming conventions are horrible. Second, if I understand what you are trying to do, you should either access the variable through your instance of the class, OR make your variable static. Be warned, making it static will make all instances share the same variable.

I love this user <3
Spoiler (Click to View)
(Mar 28, 2013 01:46 AM)Black‌jack Wrote:  First, your naming conventions are horrible. Second, if I understand what you are trying to do, you should either access the variable through your instance of the class, OR make your variable static. Be warned, making it static will make all instances share the same variable.

This. Please learn proper naming conventions. And as the user above me stated, static variables are bad, so make them "instances". If you wish to take input in one class, pass the inputs to the class you wish to use them in.

~ Singularity ~
[Image: 9N6Aq1f.gif]

(Mar 28, 2013 04:21 AM)vitafortis Wrote:  This. Please learn proper naming conventions. And as the user above me stated, static variables are bad, so make them "instances". If you wish to take input in one class, pass the inputs to the class you wish to use them in.

Static variables aren't bad as such... They have their uses.. they should generally be used for constant variables that aren't changing in different instances of classes.

Use of setters and getters is a nice way to manage variables in different class instances and will help keep code clean.
(Mar 28, 2013 04:35 AM)๖ۣۜSerendipity Wrote:  Static variables aren't bad as such... They have their uses.. they should generally be used for constant variables that aren't changing in different instances of classes.

Use of setters and getters is a nice way to manage variables in different class instances and will help keep code clean.

Well yes, but most cases that you have "static variables" you can typically declare finals, unless you mean you wish to have a static variable dynamically set each time you make the FIRST instance, or wish to change it for all instances at a later time. I haven't seen very many uses where this makes sense, usually when I do something that needs something like that, I have the parent class have a variable the others inherit and only the parent class has access to change it. But that's just me.

~ Singularity ~
[Image: 9N6Aq1f.gif]



Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by pro_fesnoobSep 24, 2022 04:24 PM 14 797 Sep 24, 2022 04:24 PM
Last Post: BinaryFox
[C#] by john ronaldsadJul 20, 2022 06:49 PM 4 238 Jul 20, 2022 06:49 PM
Last Post: john ronaldsad
[Python] by Freed0m36Nov 21, 2018 08:01 AM 5 146 Nov 21, 2018 08:01 AM
Last Post: Infamia