2016/1/17 private public protected 权限练习

 1 package caipiao;
 2 
 3 private class Test0117 {
 4  
 5  private String title;
 6  public String actor;
 7  protected String director;
 8  private int price;
 9  String review;
10  
11  
12  public String getTitle(){  //权限 私有转公共:  权限 类名  get()
13      return title;
14  }
15  public int getPrice(){
16      return price;
17  }
18  public String getDirector(){
19      return director;
20  }
21  
22 private int dianying(int a ,int b){
23      price = a+b;
24      return price;
25  }
26  
27  
28  
29  
30  // 无参构造方法  默认是无参   但如果有参  下面又需要无参的构造方法 必须加上无参的构造方法
31      Test0117(){
32          
33      }
34 
35     public Test0117(String a,String b,String c,int d,String e){
36         this.title=a;
37         this.actor=b;
38         this.director=c;
39         this.price=d;
40         this.review=e;
41      
42  }
43 
44     
45     
46     public static void main(String[] args){
47         Test0117 film=new Test0117("星球大战7","哈里森·福特 马克·哈米尔 凯丽·费雪 亚当·德赖弗 黛西·雷德利","J·J·艾布拉姆斯",
48                 75,"  恩多战役结束后,义军同盟改组为新共和国,
         钱德里拉行星成为临时首都。银河议会得到恢复。
         蒙·莫思马被选为新共和国银河议会首任议长。
         新共和国星际舰队由贾尔·阿克巴元帅指挥。
         几个月后,新共和国在阿基瓦行星上空...");
49         System.out.println("电影名称:"+film.title);
50         System.out.println("演员:    "+film.actor);
51         System.out.println("导演:    "+film.director);
52         System.out.println("票价:    "+film.price+"元");
53         System.out.println("故事概要  "+film.review);
54     }
55 }

 

原文地址:https://www.cnblogs.com/haodayikeshu/p/5138076.html