Online Java Compiler By
JavaTpoint.com
//import statements? package Class; import java.util.Collection; public class ClassgetPackageExample2 { public static void main(String... args) { Class
class1 = ClassgetPackageExample2.class; Package pkg = class1.getPackage(); // String pkgs = class1.getPackage().toString(); System.out.println(pkg.getName()); Class
class2 = Collection.class; Package pkg2 = class2.getPackage(); System.out.println(pkg2.getName()); } }
Output