Answers for "import class from package java"

2

import class java

//Demo.java  
package pack;  

public class Demo {  
    public void msg() {
        System.out.println("Hello");
    }  
}  


//Test.java  
package mypack;  

import pack.Demo;  

class Test {  
    public static void main(String args[]) {  
        Demo obj = new Demo();  
        obj.msg();  
    }  
}
Posted by: Guest on April-05-2022
0

import class from package java

Package can have many classes but sometimes we want to access only specific class in our program in that case, Java allows us to specify class name along with package name. 
If we use import packagename.classname statement then only the class with name classname in the package will be available for use.
Posted by: Guest on May-10-2022
-2

import class java

import package.myclass;
Posted by: Guest on December-18-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language