Chapter 3
Chapter 3
2. In contrast, reference type determines The real object type in the run-time,
which overloaded method will be used not the reference variable's type,
at compile time. determines which overridden method
is used at runtime
Final variable:
1. The value of a final variable cannot be changed.
2. Final variable behaves like class variables and they do not take any space on
individual objects of the class.
3. Example of declaring final variable:
final int size = 100;
8.Define package. How to create user defined package? Explain with example
Ans.
1. Java provides a mechanism for partitioning the class namespace into more
manageable parts.
2. This mechanism is the package.
3. The package is both naming and visibility controlled mechanism.
4. Package can be created by including package as the first statement in java source
code.
5. Any classes declared within that file will belong to the specified package.
6. Package defines a namespace in which classes are stored.
7. Syntax:
package pkg; Here, pkg is the name of the package
8. Example:
package mypack;
9. Packages are mirrored by directories.
10. Java uses file system directories to store packages.
11. The class files of any classes which are declared in a package must be stored in a
directory which has same name as package name.
12. The directory must match with the package name exactly.
13. A hierarchy can be created by separating package name and sub package name by
a period(.) as pkg1.pkg2.pkg3; which requires a directory structure as pkg1\pkg2\
pkg3.
14. Syntax: To access package In a Java source file, import statements occur
immediately following the package statement (if it exists) and before any class
definitions.
15. Syntax: import pkg1[.pkg2].(classname|*)