Java Demo 5: Package and Import Keyword In Java

Поділитися
Вставка
  • Опубліковано 19 вер 2024
  • Package in Java:
    Packages in java are used to organize related or similar classes, interface, and enumerations into one group. for example, java.sql package has all classes needed for database operation. Packages are also used to avoid naming conflict between the classes. Using package, you can give same name to different classes.
    - packages are declared using keyword ‘package’. They should be declared in the first statement in a java. If you try to declare packages at any other statements, you will get compile time error.
    package com;
    class A{
    //some statements
    }
    Import Statement in Java:
    If you want to use the member of package in another package, then you have to refer it through package name like below;
    import pack1.*;

КОМЕНТАРІ •