Answers for "java get package name of java file"

0

Using java packagename.*

//If you use package.* then all the classes and interfaces of this package will be accessible but not subpackages. 

The import keyword is used to make the classes and interface of another package accessible to the current package.

//save by A.java  
package pack;  
public class A{  
  public void msg(){System.out.println("Hello");}  
}  

//save as B.java
package mypack;  
import pack.*;  //Importing the package named pack which contains class A.
  
class B{  
  public static void main(String args[]){  
   A obj = new A();  
   obj.msg();  
  }  
}
Posted by: Guest on August-31-2021
0

Using java packagename.*

//If you use package.* then all the classes and interfaces of this package will be accessible but not subpackages. 

The import keyword is used to make the classes and interface of another package accessible to the current package.

//save by A.java  
package pack;  
public class A{  
  public void msg(){System.out.println("Hello");}  
}  

//save as B.java
package mypack;  
import pack.*;  //Importing the package named pack which contains class A.
  
class B{  
  public static void main(String args[]){  
   A obj = new A();  
   obj.msg();  
  }  
}
Posted by: Guest on August-31-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language