473,385 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Refer to that Red planet Object...(outside the method it's in)

nomad
664 Expert 512MB
Hello Everyone:
I back trying to learn Java again.
Here is what I'm trying to do.
1. How does the code inside the visitPennsylvania method refer to the variable with vale "red Planet".
I know to that you need to use. this.
But I can not figure out how to use it.
Here are my two class.
Expand|Select|Wrap|Line Numbers
  1.  import static java.lang.System.out; 
  2. public class EnglishSpeakingWorld {
  3. String mars = " red planet";
  4. void visitPennsylvania() {
  5. out.println("visitPA is running:");
  6. String mars = "Janine's home town";
  7. out.println(mars);
  8. out.println(this.mars);
  9.  
  10. }
  11.  
  12.  
Expand|Select|Wrap|Line Numbers
  1.  import static java.lang.System.out; 
  2. public class GetGoing {
  3. public static void main (String args[]) {
  4. out.println("main is running:");
  5. EnglishSpeakingWorld e = new EnglishSpeakingWorld();
  6. out.println(e.mars);
  7. e.visitPennsylvania();
  8.  
  9.  
Thanks
nomad
PS this is not a class project....
Jan 25 '08 #1
2 1213
BigDaddyLH
1,216 Expert 1GB
Hello Everyone:
I back trying to learn Java again.
Here is what I'm trying to do.
1. How does the code inside the visitPennsylvania method refer to the variable with vale "red Planet".
I know to that you need to use. this.
But I can not figure out how to use it.
Here are my two class.
Expand|Select|Wrap|Line Numbers
  1.  import static java.lang.System.out; 
  2. public class EnglishSpeakingWorld {
  3. String mars = " red planet";
  4. void visitPennsylvania() {
  5. out.println("visitPA is running:");
  6. String mars = "Janine's home town";
  7. out.println(mars);
  8. out.println(this.mars);
  9.  
  10. }
  11.  
  12.  
Expand|Select|Wrap|Line Numbers
  1.  import static java.lang.System.out; 
  2. public class GetGoing {
  3. public static void main (String args[]) {
  4. out.println("main is running:");
  5. EnglishSpeakingWorld e = new EnglishSpeakingWorld();
  6. out.println(e.mars);
  7. e.visitPennsylvania();
  8.  
  9.  
Thanks
nomad
PS this is not a class project....
Works for me. Are you sure you compiled and ran your latest version?
Jan 25 '08 #2
nomad
664 Expert 512MB
Works for me. Are you sure you compiled and ran your latest version?
To much reading and I'm tried.
I was think from the [color=#000000]class[/color] GetGoing.
to println this.mars

nomad
Jan 25 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Ivo | last post by:
How do I make the magic 'this' variable refer to an object of my choice, in a string of code which is to be eval'ed? Say, I have an object, an array with four elements: var myobject = ; and a...
5
by: kuvpatel | last post by:
Hi I want to refer a class called LogEvent, and use one of its methods called WriteMessage without actually having to create an instance of Logevent. I have tried using the word sealed with...
1
by: Epson Barnett | last post by:
Hi, I'm new to C# and I'd like to be able to reference a field of an object using a variable instead of literal text. In the PHP scripting language, you can create a variable: $var = "name";...
2
by: Dean Slindee | last post by:
Is there any way to refer to the .text property of a status bar panel thru object syntax, like below (the inner "for" does not work): Public Function FormStatusBarPaint(ByVal frm As Form)...
8
by: Sullivan WxPyQtKinter | last post by:
When debugging using 'print' statement, I usually want to print some important values together with the function name as the context of the values printed out. So my hope is that I could get the...
10
by: Bill Nguyen | last post by:
I have several textbox controls in a form,. I name them txt1, txt2, ... txt10. How dow I refer to them in a loop to get the value in text proerty of each control? For x = 1 to 10 value =...
1
by: Peter Rilling | last post by:
Hi. I am using Atlas and hooking a load event using add_load(...). This is being called from the constructor of an object being created, so it is within the context of an object (where 'this'...
1
by: john | last post by:
LINQ works a lot like an Access DB Recordset in the way it functions, one of the things I could do in Access is refer to the Fields thru a Variable as below allowing me to Iterate over the...
8
by: Andy B | last post by:
Is there a way to refer to things in Session object without calling Session itself?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.