复制代码
- //:Cookie.java
- //Createsalibrary
- packagec05.dessert;
- publicclassCookie{
- publicCookie(){
- System.out.println("Cookieconstructor");
- }
- voidfoo(){System.out.println("foo");}
- }///:~
复制代码
- //:Dinner.java
- //Usesthelibrary
- importc05.dessert.*;
- publicclassDinner{
- publicDinner(){
- System.out.println("Dinnerconstructor");
- }
- publicstaticvoidmain(String[]args){
- Cookiex=newCookie();
- //!x.foo();//Cantaccess
- }
- }///:~
复制代码
- //:Cake.java
- //Accessesaclassinaseparate
- //compilationunit.
- classCake{
- publicstaticvoidmain(String[]args){
- Piex=newPie();
- x.f();
- }
- }///:~
复制代码
- //:Pie.java
- //Theotherclass
- classPie{
- voidf(){System.out.println("Pie.f()");}
- }///:~
欢迎光临 仓酷云 (http://ckuyun.com/) | Powered by Discuz! X3.2 |