Solved

Variable HELP

Posted on 2000-02-26
2
170 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

623 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