Skip to main content

Posts

Showing posts with the label Packages and Imports

Packages and Imports

Packages and Imports: Packages are directories with classes and methods, Import used to get the classes and methods from Inbuilt or created packages. Syntax:                                       import package_name; Here is the Code: //Package myPackage; (directory) // Java file in drive:Main.java import myPackage; class Main { public static void main (String[] args) { A a = new A(); a.getMe(); } } // Java file in drive:/myPackage/A.Java  package myPackage; public class A  {     public static void getMe()     {         System.out.println("Thank you");     } } /* compile:/myPackage> javac A.java  compile: javac Main.java  run: java Main  Output: Thank you */ Here is the Video: