• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 169
  • Last Modified:

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

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
polkadot
Asked:
polkadot
  • 2
1 Solution
 
objectsCommented:
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
 
polkadotAuthor Commented:
oh, how do I create a package?

and how do I do it with eclipse or without it?
0
 
objectsCommented:
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

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now