Abstract, Interface, or Package
Abstract
Abstract
method
An abstract method is a special type of superclass method which body is unimplemented. The body of
the abstract method is implemented of the derived class.
Abstract class
Interface
The interface is a special
type class that contains only abstract methods. We cannot create the object
of an interface. It can be only inherited by class. To inheritance the
properties of an interface we have to use a special keyword “Implements”
instead of extends.
A package is nothing
but a similar type of java programs. Packages works like directory in DOS, folder
in the windows. By using packages the program organization can be done very
easily. Class name can be reusable among the packages.
There is several
following advantage of package concept
- Packages are useful to arrange related classes and interfaces into a group. This makes all the classes and interfaces performing the same task to put together in the same package. For example, in java all the classes and interfaces which perform input and output operations are stored in java.io package.
- Packages hide the classes and interfaces in a separate sub directory, so that accidental deletion of classes and interfaces will not take place.
- The classes and
interfaces of a package are isolated from the classes and interfaces of other
package. This means that we can use same names for classes of two different classes.
for example, there is a date class in java.util package and also there is
another date class available in java.sql package.
Packages are of two types:-
- Predefined packages or built in packages.
- User defined package or custom package.
Predefined Packages
Built in packages are developed by somebody else and
we can able to use directly. In java software the predefined packages are
- java.applet
- java.awt
- java.io
- java.lang
- java.net
- java.util
- java.swing.
User Defined Packages
User define package are
use for user built package, Right side of page show how work user define
packages. First create main Folder PackageExampleFile
and create sub-folder PackageClassFile
and also create Main.java code here. In the PackageClassFile have more
class like FirstClassFile.java, SecondClassFile.java
Compile and Run “MainClassFile.java”
No comments:
Post a Comment