Answers for "how java package name"

1

naming a package java

//if your domain name is google.com, name your package as com.google so that your package is unique across the world as domain names are unique
package com.google
Posted by: Guest on February-27-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
1

naming a package java

//if your domain name is google.com, name your package as com.google so that your package is unique across the world as domain names are unique
package com.google
Posted by: Guest on February-27-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