-6

I know what the difference between private, public and protected. but I don't know what the difference between private field and filed without any access modifiers.

class Example{
private int field1;
int field2;
}
user3376321
  • 819
  • 2
  • 8
  • 21
  • 5
    Please see the [Java tutorial on "Controlling Access to Members of a Class"](http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html). – rgettman May 08 '14 at 23:55
  • Just. Make. An effort. http://i.stack.imgur.com/lCSkm.png – Jeroen Vannevel May 08 '14 at 23:58
  • http://stackoverflow.com/questions/215497/in-java-whats-the-difference-between-public-default-protected-and-private?rq=1 – assylias May 09 '14 at 00:26

1 Answers1

2

In Java if you leave the access specifier off then the member is "package" level. Package level members can be seen by the class that defines the member and other classes in the same package. The difference between that and private are private members may only be seen by the class which defines it.

Jeff Scott Brown
  • 22,358
  • 1
  • 26
  • 42
  • 2
    This is perfectly correct, of course; but it would be interesting to know what the downvoter was thinking. – Dawood ibn Kareem May 08 '14 at 23:58
  • I have only started participating here in the last few weeks and a lot of that is mysterious to me. This question is perfectly valid and at the moment it is -4. The answer here seems perfectly appropriate and it is currently -1. – Jeff Scott Brown May 08 '14 at 23:59
  • Someone is perhaps trying to ward off point farmers who answer questions that they feel should not have been asked? It would have been more appropriate to flag the question as one that did not demonstrate a basic understanding of the issue rather than flagging a correct answer. – MarsAtomic May 09 '14 at 00:08
  • downvoters usually don't leave comments (although they should). Unfortunately there is not much you can do about that (only speculation) @JeffScottBrown – donfuxx May 09 '14 at 00:08
  • Thank you for your answer :) – user3376321 May 09 '14 at 00:10
  • I think I will stop responding to questions except Grails questions that go unanswered for a while or that I have particular expertise with. While I thought addressing fundamental questions would be helpful to the community, it has only proved frustrating. Learning... – Jeff Scott Brown May 09 '14 at 00:12
  • 1
    @JeffScottBrown I think the -4 is because the OP could have easily found the answer in a reference or tutorial. The -1 is probably as MarsAtomic said; there's a big discussion going on about what to do about "low-quality" questions like this, and likely some people are trying to discourage others from answering them. It's not the way I think it should be handled. – ajb May 09 '14 at 00:12
  • 1
    @JeffScottBrown please don't stop responding to questions like this one. Your input here is valuable. The fact that you've accumulated almost 800 reputation in less than four weeks reflects this. And of course, in this instance, you've definitely helped the OP. Don't be put off by one person who doesn't understand what downvoting is for. – Dawood ibn Kareem May 09 '14 at 03:48
  • 1
    Downvoter on the question because it is covered in [Java Tutorials. Controlling Access to Members of a Class.](http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html). Not downvoter of this answer because it covers what OP asks. – Luiggi Mendoza May 09 '14 at 05:09
  • 1
    @DavidWallace I am not going to stop answering questions altogether. I have just decided to stick primarily to Groovy and Grails questions and stop looking at basic Java questions that a million other folks can deal with. I thought helping beginners would be beneficial for them and rewarding for myself. I was wrong. – Jeff Scott Brown May 09 '14 at 11:39