Solved

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

Posted on 2006-06-15
3
160 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

757 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

21 Experts available now in Live!

Get 1:1 Help Now