Sunday, May 9, 2021

Abstract, Interface or Package (Experience in java)

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

An abstract class is a special type of class in which an object cannot be created. It is only inherited be subclass if a class containing at least one abstract method then that class will be abstract automatically.


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.

If a class inheritance the properties of an interface then we must have to implement all methods of the interface otherwise that class becomes abstract

Package


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

  1. 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.
  2. Packages hide the classes and interfaces in a separate sub directory, so that accidental deletion of classes and interfaces will not take place.
  3. 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

  1. java.applet
  2. java.awt
  3. java.io
  4. java.lang
  5. java.net
  6. java.util
  7. 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:

INTRODUCTION TO COMPUTER NETWORKS

A Computer network consists of two or more autonomous computers that are linked (connected) together in order to: • Share resources (files...