1. 程式人生 > >Java編程思想讀書筆記_第6章(訪問權限)

Java編程思想讀書筆記_第6章(訪問權限)

ack string 屬於 cte pri 包訪問權限 print code int

四種訪問權限:

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章(訪問權限)