1

WebView class is final. It contains method getChildren(), which is protected.

How to use it then?

UPDATE

The question is not about protected adn/or final keywords, but about why this is done this way? What is the reason to have protected members in final classes?

Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385

4 Answers4

1

protected means "package and inheritance access" so classes in the same package can access this method.

EDIT:

answer to your edit: it's because designers of this class wanted this method to be available ONLY to classes within the same package and no other classes (thus you cannot extend it because their made it final)

Lucas
  • 3,181
  • 4
  • 26
  • 45
  • Actually, you could still argue that it makes more sense to use the default visibility (no modifier). That explicitly means "only classes in this package" and is identical to protected if no subclasses can exist. – James_D Jan 03 '14 at 17:25
0

When it declared as protected, Still the classes who instantiate the WebView class in the same package can use that method.

You might think that it cannot be extended as it is final, there is no way to access it outside of the class. Yes, that is true but with in the package, they can.

Modifier    Class   Package Subclass    World
---------------------------------------------
protected   Y      **Y**        Y           N
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
0

As you know, final classes cannot be extended. A final class can not be subclassed.

protected Modifier - Accessed by other classes in the:

  • same package
  • any subclasses of the class in which they are referred (i.e. same package or different package).
Maxim Shoustin
  • 77,483
  • 27
  • 203
  • 225
0

You can't extend it because it's final.

  • Create and instance of Webview class and call newWebViewInstance.getChildren().
  • You can create a package with the same package of Webview, but anybody with right sense of Java programming language wouldn't do it.

Update

I don't like to make member/methods of a final class protected . IMHO that is bad programming practise unless in this case.

Why was it made protected?

WebView extends javafx.scene.Parent

And getAllChildren() is an method of javafx.scene.Parent which is of protected scope.

protected javafx.collections.ObservableList<javafx.scene.Node> getChildren()

As we now know Webview is a subclass of javafx.scene.Parent and overrides getChildren(). If it changes the scope (default being stricter than protected) it breaks the overriding contract.

Hope it's clear now.

avijendr
  • 3,958
  • 2
  • 31
  • 46