首页 > 代码库 > Java编程思想读书笔记_第6章(访问权限)

Java编程思想读书笔记_第6章(访问权限)

四种访问权限:

public private 包访问权限 protected

如果没有明确指定package,则属于默认包

 1 package access.dessert;
 2 
 3 public class Cookie {
 4     public Cookie() {
 5         System.out.println("Cookie()");
 6     }
 7     
 8     void bite() {
 9         System.out.println("bite");
10     }
11 }
12 
13 class Demo {
14     
15 }
16 
17 //private class Demo1 { 
18 //不支持private 类    
19 //}
20 
21 //protected class Demo2 {
22 //不支持protected 类
23 //}
 1 package access.dessert;
 2 
 3 public class Cake {
 4     public static void main() {
 5         Cookie c = new Cookie();
 6         c.bite();
 7         
 8         Demo d = new Demo();//包访问权限
 9     }
10 }
1 public class Egg {
2     public static void main() {
3         //Cookie c = new Cookie();
4     }
5 }
 1 import access.dessert.*;
 2 
 3 public class Dinner {
 4     public static void main(String[] args) {
 5         Cookie c = new Cookie();
 6         //c.bite();
 7         
 8         //Demo d = new Demo();
 9     }
10 }

 

Java编程思想读书笔记_第6章(访问权限)