如何运行存储在两个不同程序包中的两个文件 [英] How to Run two files which are stored in two different packages

查看:82
本文介绍了如何运行存储在两个不同程序包中的两个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨...

我正在尝试在dos promt中运行两个文件,这些文件存储在两个不同的程序包中...

两个文件都相互中继...

我正在尝试设置类路径,但没有确切的方法...

Hi...

I,m trying to run two files in dos promt,which are stored in two different packages...

both files are relay on each other...

I''m trying to set class path but not getting exact way...

package p1;
class Box
{
    //public static void main(String args[]){
    int w=12;
    int d=30;
    int c=40;
//}
}

package p2;
import p1.Box;
class Demo
{
    public static void main(String[] args)
    {
        Box b=new Box();
        System.out.println("Hello World!");
    }
}

推荐答案

将这两个类都设置为公共类,如果它不是公共的,则不能访问包外部的类.至少将Box类设置为public

Make both class as public,you cant access class outside the package if it is not public.Atleast make Box class as public

package p1;
public class Box
{
//public static void main(String args[]){
int w=12;
int d=30;
int c=40;
//}
}




命令是java -cp c:\ validation p2.Demo

其中c:\ validation文件夹是同时存在p1和p2文件夹的地方.




Command is java -cp c:\validation p2.Demo

where c:\validation folder is where both p1 and p2 folders are present.


这篇关于如何运行存储在两个不同程序包中的两个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆