1.

Explain The Public Class Modifier.

Answer»

As you DEVELOP Java programs, there may be times when you create classes that you don't WANT the code outside of the class package (the class file) to access or even to have the knowledge of.
When you USE the public keyword WITHIN a class DECLARATION, you make that class visible (and accessible) everywhere. A non-public class, on the other hand, is visible only to the package within which it is defined. To control access to a class, do not include the public keyword within the class declaration. Java only lets you place one public class within a source-code file. For example, the following statement illustrates the use of the public keyword within a class:

public class ImEverywhereYouWantMeToBe { }

As you develop Java programs, there may be times when you create classes that you don't want the code outside of the class package (the class file) to access or even to have the knowledge of.
When you use the public keyword within a class declaration, you make that class visible (and accessible) everywhere. A non-public class, on the other hand, is visible only to the package within which it is defined. To control access to a class, do not include the public keyword within the class declaration. Java only lets you place one public class within a source-code file. For example, the following statement illustrates the use of the public keyword within a class:



Discussion

No Comment Found