17 Sep 2012, 13:08
A - flowers - 07_pragsmall

S. S. M. A. E (1 post)

Hi everybody.

Each java file with onCreate() method in this book, has PROTECTED access modifier, except the mainActivity (,that has PUBLIC onCreate.) Why they are “protected”?? i seek complete explaination, please.

Thanks for any idea. :)

04 Dec 2012, 15:39
Generic-user-small

Dmitriy Rodionov (2 posts)

Hi! I’m not a Java developer, but I suppose it has been made for the purpose of components sharing. As you might know, Android supports components sharing. Maybe you should mark onCreate() method as PUBLIC only when you want the Activity it creates to be shared other applications. I’m not sure…:-(

14 Apr 2013, 01:56
Burnette_ed_pragsmall

Ed Burnette (1316 posts)

In the book examples there was no good reason to make things public, protected, or private. In a real program, especially one with multiple developers, you should get in the habit of using the most restrictive access possible. Take a look at this:

  • http://stackoverflow.com/questions/215497/in-java-whats-the-difference-between-public-default-protected-and-private
  • http://en.wikibooks.org/wiki/Java_Programming/Scope
  • http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html
  You must be logged in to comment