Solved

public protected ... what is the best way to do this?

Posted on 2006-06-15
3
162 Views
Last Modified: 2010-03-31
for example, if I have something like:

public class LotteryTicket{

public Vector numbers;
...
}

public class LotteryTicketGenerator{

...
public void someMethod(){
... LotteryTicket.numbers.get(0)...
}


How can I give LotteryTicketGenerator access to LotteryTicket class without giving all classes access?


0
Comment
Question by:polkadot
  • 2
3 Comments
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 16917685
put it in the same package and make it package protected

    Vector numbers;

or just protected if you want to also give subclasses access to

   protected Vector numbers;
0
 

Author Comment

by:polkadot
ID: 16917712
oh, how do I create a package?

and how do I do it with eclipse or without it?
0
 
LVL 92

Expert Comment

by:objects
ID: 16918126
to create a pcakge you add package statement to top of source

package com.polkadot;

public class LotteryTicket{

Vector numbers;
...
}

And put your source in a directory hierarchy that matches the package hierarchy

eg.  /src/java/com/polkadot/LoteryTicket.java

In Eclipse you can create a new package via new>package
And refactor to move the class into package
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse java  build path 6 56
Apps blocked by Java 9 79
MySqlDump not dumping triggers 1 30
hibernate jars 4 27
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

813 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

18 Experts available now in Live!

Get 1:1 Help Now