Modifiers and permissions

Source: Internet
Author: User
Tags modifiers

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.