CATEGORII DOCUMENTE |
Asp | Autocad | C | Dot net | Excel | Fox pro | Html | Java |
Linux | Mathcad | Photoshop | Php | Sql | Visual studio | Windows | Xml |
The protected access specifier requires a jump ahead to understand. First, you should be aware that you don't need to understand this section to continue through the book up through the inheritance chapter. But for completeness, here is a brief description and example using protected.
The protected keyword deals with a concept called inheritance, which takes an existing class and adds new members to that class without touching the existing class, which we refer to as the base class. You can also change the behavior of existing members of the class. To inherit from an existing class, you say that your new class extends an existing class, like this:
class Foo extends Bar
public static void main(String[] args)
One of the interesting things about inheritance is that if a method foo( ) exists in class Cookie, then it also exists in any class inherited from Cookie. But since foo( ) is "friendly" in a foreign package, it's unavailable to us in this one. Of course, you could make it public, but then everyone would have access and maybe that's not what you want. If we change the class Cookie as follows:
public class Cookie
protected void foo()
then foo( ) still has "friendly" access within package dessert, but it is also accessible to anyone inheriting from Cookie. However, it is not public.
Politica de confidentialitate | Termeni si conditii de utilizare |
Vizualizari: 654
Importanta:
Termeni si conditii de utilizare | Contact
© SCRIGROUP 2024 . All rights reserved