Solved

Variable HELP

Posted on 2000-02-26
2
166 Views
Last Modified: 2013-11-20
Hi,

 If I have a variable in a class,
 how can I get the value of this variable in another class ?
0
Comment
Question by:RogerioSilva
2 Comments
 
LVL 2

Accepted Solution

by:
bbousquet earned 50 total points
ID: 2561245
You have a number of choices for doing that:

1. If your 2nd class knows an instance of the 1st one, make the variable public

2. If your 2nd class knows only the structure of the 1st class, you can make the variable static

3. If your 2nd class knows an instance of the 1st one, but the variable is private/protected, you can always make the two classes friends (which I don't really recommend)

4. If your 2nd class knows an instance of the 1st one, you can add a public method to the 1st class which returns the value of the variable.

5. If your 2nd class derives from the 1st class, and the variable is protected, you can access it transparently.

Take your pick!
0
 
LVL 1

Author Comment

by:RogerioSilva
ID: 2561249
thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 122
repeateFront java challenge 31 92
windows 10 how make picture as desktop background 2 62
abstract class with all non abstract mentods 6 76
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question