6

While reading the "Hello, Android" book, I noticed that:

each java file with onCreate(Bundle savedInstanceState) method, has protected access modifier EXCEPT in the main Activity of the program [that has: public void onCreate(Bundle savedInstanceState)].

Why is the onCreate method public on the program's main Activity, but protected everywhere else?

GargantuChet
  • 5,691
  • 1
  • 30
  • 41
Soroor
  • 109
  • 2
  • 7

3 Answers3

1

You can change the visibility of a method. What you cannot do is : reduce the visibility (make a public method private), access a private method (making it public)

njzk2
  • 38,969
  • 7
  • 69
  • 107
0

It can as well be protected. There is nothing important or wise about that.

Alexander Kulyakhtin
  • 47,782
  • 38
  • 107
  • 158
0

There is no reason to make the method public (but doing so doesn't affect anything). You shouldn't call it manually anyway.

By the way Intellij IDEA have Activity template with public onCreate. This may be the reason this method public in the book.

Vladimir Petrakovich
  • 4,184
  • 1
  • 30
  • 46