Thursday 11 June 2015

Packages in Java

Package and Interface:
Very first statement of the source file.
There has to be a folder with the same name as that of every package.
package p1;
class A
{}
class B
{}

The folder containing these files should also be named p1.
After moving out of the folder containing the package in cmd.

Access Specifiers:
public:
Accessible in all parts of the packets and even across the packet.
Protected:
It behaves similarly as public members within a package.

Across the package it is inherited but cannot be used directly through the object
Private:
Accessible only within the class.
No specifier:
behaves like public within a package

same as private across the package

To extend a class across packages, the class has to be public and its constructor has to be public. And the name of the file containing the to be extende class should be the same as the class name.

One source file can have only one public file.

packages from different folders can be imported just by setting classpath to the location of the package folder.

Javadoc:
converts everything inside the documentation comments into an XML file.

No comments:

Post a Comment