Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2006-06-15
3
Medium Priority
?
167 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 2000 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

972 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