There are two types of modifiers for a method:
1. Access control modifier (public,private,protected, default)
2. Method itself modifier (static,final,abstract,)
Modifiers for the class:
1. Prefix modifier (public,abstract,final)//j A Java source file, which specifies that there can be at most one public class, or none of them. If there is a public common class, the specified file name can only be the same as the public class name, if not, the file name is arbitrary. The class that is the portal (javase) of a Java program must be a public class.
2. Suffix modifier (extends,implements)
—————————————————————————————————————————————————————————————————————————————
|
Private |
Default |
Protected |
Public |
In the same class |
√ |
√ |
√ |
√ |
In the same package |
|
√ |
√ |
√ |
Sub-class |
|
|
√ |
√ |
Global scope |
|
|
|
√ |
Access rights: High —————————————————————————————————— > Low
Question1: Subclass overrides the access modifier of a method of a parent class, not lower than the method access permission of the parent class
Class fu{ private void xx () { syso ... }} Class Zi extends fu{ public void xx () //This completely cannot find the private method, so the subclass modifier access permission to (greater than or equal to) the parent class modifier access rights { Syso... }}
Question 2: Can subclasses override the parent class method?? (that is, subclasses can inherit the parent class method, overwrite it?) )
Answer 2: Yes, but be sure to avoid the following conditions
Class fu{public void xx () {} }class Zi extends fu{public int xx () {} }
Class Demo
{
public static void Main (String arg [])
{
Zi zi=new Zi ();
ZI.XX ()//At this time do not know exactly what to call the XX ()
}
}
Modifiers and permissions