Protected
Only variables and methods may be declared protected. A protected feature of a class is available to all classes in the same package, just like a default feature. However, a protected feature of a class is available to all subclasses of the class that owns the protected package.
All java source files are related to a "package", when you work with files within a single working directory, you work under a "default" package, that is distinct from other packages, such as my_dog_package in this case.
If the class Dog was within the Canine.java source file, the class Dog would belong to the "default" package. In order for you to import the Dog class from a "foreign" package, you must declare the class public. But that's not all, let's see a more complex example:
This modifier may be applied only to:
The compiler insists that a class must be abstract if:
- The class has one or more abstract methods.
- The class inherits one or more abstract method (from an abstract parent) for which it does not provide implementations.
- The class declares that it implements an interface but does not provide implementations for every method of that interface.
Basic rules for static methods:
- A static method may only access the static data of its class; it may not access non-static data.
- A static method may only call the static methods of its class; it may not call non-static methods.
- A static method has no this
- A static method may not be overridden to be non-static.
- transient
0 comments:
Post a Comment