?
Solved

java package, multiple classes 1 source file question

Posted on 2006-06-10
1
Medium Priority
?
318 Views
Last Modified: 2010-04-17
hey-- a simple question for somebody. essentially, i'm trying to figure out some package basics here so i can access a public variable across multiple classes. so, how do i make this work: (comments in caps below)

package reader_pp;
import java.util.*;

public class Tester {
   
    public static String huh;
   
     public static void main (String[] args) {
         huh = "huh";
        new Tester().tester1();
       
     }  
       
     public void tester1 () {
         
           System.out.println(huh);
           TestPrint testtt = new TestPrint( );
           //new TestPrint.TestPrint();
       }  
}

class TestPrint{
   
    TestPrint( ) {
        System.out.println("need to print here");
       
         //ULTIMATELY I NEED TO ACCESS VARIABLES HERE THAT ARE DEFINED IN THE PUBLIC CLASS tester such as the varibale: huh
        System.out.println(huh);
    }
   
   
   
}

0
Comment
Question by:jacobbdrew
[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
1 Comment
 
LVL 25

Accepted Solution

by:
InteractiveMind earned 2000 total points
ID: 16878084
When the variable is static:

Tester.huh

Otherwise:

(new Tester()).huh
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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Progress
Suggested Courses
Course of the Month8 days, 9 hours left to enroll

764 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