java面试题三十 public,private,protected,default访问权限
生活随笔
收集整理的這篇文章主要介紹了
java面试题三十 public,private,protected,default访问权限
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1 考題描述:
?
2 答案
BD
?
3解析
B. no modifer既為default也就是friendly
?
3.1 public,private,protected,default訪問權限圖
3.2證明
?3.2.1 myeclipse類關系圖如下
?
3.2.2 各個類的代碼
Student.java
package com.inner;public class Student {public String name = "zhangsan";String email = "1254290201@qq.com";protected int age = 13;private String address = "廣州";public static void main(String[] args) {Student student = new Student();System.out.println("name = " + student.name);System.out.println("email = " + student.email);System.out.println("age = " + student.age);System.out.println("address = " + student.address);}}?
MyTest1.java
package com.inner;public class MyTest1 {public static void main(String[] args) {Student student = new Student();System.out.println("name = " + student.name);System.out.println("email = " + student.email);System.out.println("age = " + student.age);System.out.println("address = " + student.address); //這行編譯通不過}}
MyTest2MyTest2MyTest2MyTest2.java
?
?
?
?
?
?
?
總結
以上是生活随笔為你收集整理的java面试题三十 public,private,protected,default访问权限的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java面试题二十九 多线程数据共享问题
- 下一篇: dos命令配置jdk环境