myeclipse中package包的使用

在使用面向对象技术进行大型复杂系统的设计与开发中,通常需要设计与定义许多类,这些类中有些具有复杂的关系。如何对这些类进行有效的管理,java中引入了包的概念。java中对包的管理类似与操作系统中对文件系统的目录管理,即java中通过多个层次的包把各类文件组织在一起,包的层次在计算机中保存为目录。
         今天在myeclipse中做了一个包的实验,开始照着书上的做,结果这么都调试不出来。后来通过下面的方法得到解决的。

            这个例子是这样的:现有AcPublicclass及Publicclass两个类,需要在AcPublicclass中访问类Publicclass,以下为代码                    package mypack1;
                                public class Publicclass{
                                         public int i=2;
                                         public void changex(float x){
                                          x++;
                                          System.out.println("x="+x);
                                             }
                                        }
        

                                            import mypack1.Publicclass;
                                            public class AcPublicclass {
                                             public AcPublicclass() {
                                              // TODO Auto-generated constructor stub
                                                             }

                                      public static void main(String[] args) {
                                              // TODO Auto-generated method stub
                                                          mypack1.Publicclass pc=new mypack1.Publicclass();
                                                          pc.changex(2.0f);
                                                          System.out.println("pc.i="+pc.i);
                                                            pc.i++;
                                                          System.out.println("pc.i="+pc.i);
                                                         }

                                                }
因为在myeclipse下一个工程中默认的包名为default package,AcPublicclass 就在该默认包下。现需要在该工程中建立一个包名为mypack1的包,然后把Publicclass类直接拖放进mypack1包中,再运行AcPublicclass 即可。

你可能感兴趣的:(MyEclipse)