Solved

java package, multiple classes 1 source file question

Posted on 2006-06-10
1
310 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 500 total points
ID: 16878084
When the variable is static:

Tester.huh

Otherwise:

(new Tester()).huh
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
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…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

737 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