Solved

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

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet doXXX methods 3 62
couple of eclipse 5 46
use lov values 2 61
Java: How do I open the default windows program for a given file type 3 39
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

860 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