Java Package isSealed() Method



Description

The Java Package isSealed() method returns true if this package is sealed.

Declaration

Following is the declaration for java.lang.Package.isSealed() method

public boolean isSealed()

Parameters

NA

Return Value

This method returns true if the package is sealed, false otherwise

Exception

NA

Checking a java.lang Package being Sealed Example

The following example shows the usage of java.lang.Package.isSealed() method. In this program, we've created a Package variable and assigned it java.lang package object. Then using isSealed() method, we're checking if package is sealed or not.

package com.tutorialspoint;

public class PackageDemo {

   public static void main(String[] args) {

      // get the java lang package
      Package pack = Package.getPackage("java.lang");

      // check if this package is sealed
      System.out.println("" + pack.isSealed());
   }
}

Output

Let us compile and run the above program, this will produce the following result −

false

Checking a custom Package being Sealed Example

The following example shows the usage of java.lang.Package.isSealed() method. In this program, we've created a Package variable and assigned it com.tutorialspoint package object. Then using isSealed() method, we're checking if package is sealed or not.

package com.tutorialspoint;

public class PackageDemo {

   public static void main(String[] args) {

      // get the java lang package
      Package pack = Package.getPackage("com.tutorialspoint");

      // check if this package is sealed
      System.out.println("" + pack.isSealed());
   }
}

Output

Let us compile and run the above program, this will produce the following result −

false

Checking a java.util Package being Sealed Example

The following example shows the usage of java.lang.Package.isSealed() method. In this program, we've created a Package variable and assigned it java.util package object. Then using isSealed() method, we're checking if package is sealed or not.

package com.tutorialspoint;

public class PackageDemo {

   public static void main(String[] args) {

      // get the java util package
      Package pack = Package.getPackage("java.util");

      // check if this package is sealed
      System.out.println("" + pack.isSealed());
   }
}

Output

Let us compile and run the above program, this will produce the following result −

false
java_lang_package.htm
Advertisements