Solved

newbie visibility question

Posted on 2002-04-05
7
189 Views
Last Modified: 2010-03-31
Hello all
I have a class Fred.  A Fred object has a property a and a public boolean method b().
I also have a class Barney, which is very important to a lot of other classes.  Barney's main data object is an array of Fred objects:
public Fred[][] fredArray = new Fred[8][8];
Lots of other classes need to access this array of Fred objects.
One of them, class Wilma, wants to say something like:
boolean wilmaBool = fredArray[x][y].b()
What verbiage needs to be at the top of which classes to make this happen?
I mean, I probably need stuff like import or maybe package at the top of some/all of these classes, but I'm a bit lost as to what goes where.

Thanks for your help,

Edmund
0
Comment
Question by:edmund_mitchell
7 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 6922296
 You do not have to import anything. Just put all the classes in the same package and then you can access them by simply declaring them - without importing them.

  Hope it helps.
0
 
LVL 6

Accepted Solution

by:
expertmb earned 70 total points
ID: 6922431
Hi,
 You want to access that array in other classes then you have two options
 1. Make that array static and you can access like
   Barney.fredArray[x][y].b()
 2. have the Barney object and then access
   Barney barney;
   barney.fredArray[x][y].b()
 
 As mentioned by girionis if all the classes are there in  
 same package no need to import anything. if in other
 package then you have to import.
0
 
LVL 2

Expert Comment

by:vogen
ID: 6922443
expertmb is right
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 92

Expert Comment

by:objects
ID: 6922446
What sort of a proposed answer is that???
0
 
LVL 6

Expert Comment

by:expertmb
ID: 6922517
what is this vogen?
you can post comment and dont propose somebody's comment as proposed answer.

mb...
0
 
LVL 4

Author Comment

by:edmund_mitchell
ID: 6922675
A vote of confidence in someone else's response is not an answer.
0
 
LVL 4

Author Comment

by:edmund_mitchell
ID: 6922677
Thanks
Edmund
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

820 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