Solved

java package, multiple classes 1 source file question

Posted on 2006-06-10
1
297 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
Comment Utility
When the variable is static:

Tester.huh

Otherwise:

(new Tester()).huh
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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 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…

762 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

14 Experts available now in Live!

Get 1:1 Help Now