File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package accessControl ;
22
33/**
4- * @author ls
5- *public class Student 类具备全局可见性,在其它包中也可访问
6- *一个class文件中仅能有一个public类
7- *private string name 仅在本类可见
8- *protected int score 在本类和子类可见
9- *protected setScore 方法允许被子类覆盖,并访问,但在包外仍不可被访问,
10- *即使在包外创建子类也不可访问 protected
11- *default 级别为包内可见,包外不可见
12- *总而言之,public全局可见
13- *private本类可见
14- *protected对本类,继承和保内可见
15- *default只区分包内和包外
4+ * @author ls
5+ * public class Student 类具备全局可见性,在其它包中也可访问 一个class文件中仅能有一个public类
6+ * private string name 仅在本类可见 protected int score 在本类和子类可见 protected
7+ * setScore 方法允许被子类覆盖,并访问,但在包外仍不可被访问, 即使在包外创建子类也不可访问 protected default
8+ * 级别为包内可见,包外不可见 总而言之,public全局可见 private本类可见 protected对本类,继承和保内可见
9+ * default只区分包内和包外
1610 */
1711public class App {
1812 public static void main (String [] args ) {
19- Student ming = new PrimaryStudent ("xiaoMing" );
13+ Student ming = new PrimaryStudent ("xiaoMing" );
2014 ming .showInfo ();
2115 ming .setScore (50 );
2216 ming .showInfo ();
23- ming .id = 9 ;
17+ ming .id = 9 ;
2418 ming .showInfo ();
2519 }
2620}
Original file line number Diff line number Diff line change @@ -4,18 +4,18 @@ public class Student {
44
55 private String name ;
66 protected int score ;
7-
7+
88 int id ;
99
1010 public void showInfo () {
11- System .out .println ("student Info: name-" + name + " score-" + score + " id-" + id );
11+ System .out .println ("student Info: name-" + name + " score-" + score + " id-" + id );
1212 }
1313
1414 public Student (String name ) {
1515 // TODO Auto-generated constructor stub
1616 this .name = name ;
1717 this .score = 0 ;
18- this .id = 0 ;
18+ this .id = 0 ;
1919 }
2020
2121 protected void setScore (int score ) {
@@ -35,6 +35,6 @@ public PrimaryStudent(String name) {
3535 protected void setScore (int score ) {
3636 // TODO Auto-generated method stub
3737 super .setScore (score );
38- this .score = score + 1 ;
38+ this .score = score + 1 ;
3939 }
4040}
Original file line number Diff line number Diff line change 1- package TestApp ;
2-
1+ package testApp ;
32
43import accessControl .Student ;
54
65public class Test {
76 public static void main (String [] args ) {
8- Student qiang = new Student ("XiaoQiang" );
7+ Student qiang = new Student ("XiaoQiang" );
98 qiang .showInfo ();
10- Student jun = new NewStudent ("xiaoJun" );
9+ Student jun = new NewStudent ("xiaoJun" );
1110 jun .showInfo ();
1211 }
1312
14-
1513}
16- class NewStudent extends Student {
14+ /**
15+ * @see Student
16+ * @author Administrator
17+ *
18+ */
19+ class NewStudent extends Student {
1720
1821 public NewStudent (String name ) {
1922 super (name );
2023 // TODO Auto-generated constructor stub
2124 }
25+
2226 @ Override
2327 protected void setScore (int score ) {
2428 // TODO Auto-generated method stub
You can’t perform that action at this time.
0 commit comments