Solved

java package, multiple classes 1 source file question

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
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 fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now