Author:
Daisy Williams
Nov
2
A constructor provides a convenient way to initialize a newly created object at the time of its creation. A constructor is automatically called emmediately after the creation of a new object, but before the new operator completes. All Java classes must have at least one constructor, either explicitly declared in the class or an implicit default constructor. They are typically used to create an object that is an instance of a class. It is written by using the following general syntax:
[access modifier] class name([formal parameter list]) [throws clause] {
// Body of the constructor
}
Author:
Daisy Williams
Oct
28
The package statement is used to declare packages. The word package is a keyword in Java. This statement is not technically needed to write a complete Java program. However, if it appears, it must be the first executable statement in the program. Only comments or white spaces are allowed before a package statement. There can be only one package declaration in a program. If no package declaration appears, the class will belong to the default package.
For example, the following source code file defines a class named ClassA in the package named package4:
package package4;
Author:
Daisy Williams
Sep
22
The following table summarizes the accessibility of members in various forms:
| Members/Variables |
Private | Public |
Protected |
No modifier |
| Same class | Yes |
Yes |
Yes |
Yes |
| Same package subclass | No |
Yes |
Yes |
Yes |
| Same package non-subclass | No |
Yes |
Yes |
Yes |
| Different package subclass | No |
Yes |
Yes |
No |
| Different package non-subclass | No |
Yes |
No |
No |
Permanent link to this post (48 words, estimated 12 secs reading time)