project |
content |
This work belongs courses |
https://www.cnblogs.com/nwnu-daizh/ |
Where this requirement in the job |
https://www.cnblogs.com/nwnu-daizh/p/11435127.html |
Job learning objectives |
|
Experimental details and steps
Experiment 1: In the "System.out.println (...);" comment statement required by the design code ... Alternatively, enter the code in IDE observation prompted to verify the usage of four permission modifier. (20 points)
code show as below:
Subclass code:
package zhuwenben;
public class Parent {
Private String P1 = "This is a Parent private attribute";
public String P2 = "This is a Parent public properties";
protected String P3 = "This is the Parent Protected property";
String P4 = "This is the default property Parent ";
private void pMethod1 () {
System.out.println (" Parent I used a modified method of the private modifier ");
}
public void pMethod2 () {
System.out.println (" I used Parent public modifier modification method ");
}
protected void pMethod3 () {
System.out.println (" I Parent protected modifier with the modified method ");
}
void pMethod4 () {
System.out.println (" I Parent modifier is no modification method ");
}
}
parent Code:
package zhuwenben;
class Demo {public
public static void main (String [] args) {
the Parent = parent new new the Parent ();
Son Son = Son new new ();
son.pMethod3 (); // call the method with the parent class, respectively Paren attempt, by Son class method calls the son
}
}
class Son the extends the Parent {
Private String S1 = "This is the Son private attribute";
public String S2 = "This is the Son public properties";
protected String S3 = "This is the Son Protected property";
String S4 = "This Son is the default attribute of ";
public void sMethod1 () {
System.out.println (P2); // try to display each class p1 Parent, p2, p3, p4 value
System.out.println (" I Son public use method modified modifier ");
}
private void sMethod2 () {
System.out.println (" I using the private modifier Son modified method ");
}
protected void sMethod () {
System.out.println (" I Son is modified with a modifier protected method ");
}
void sMethod4 () {
System.out.println (" I Son no modifiers modification method ");
}
}
Results are as follows: