Solved

java package, multiple classes 1 source file question

Posted on 2006-06-10
1
313 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
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 …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

690 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