Modifiers in Java and their usage

Source: Internet
Author: User
Tags modifiers

1. Modifier A in Java. Permission modifiers

Private, default, Protected,public

B. Status modifier

Static,final

C. Abstract modifiers

Abstract

2. Class modifiers

Public (access control), declare a class as a common class, he can be accessed by any object, the main class of a program must be a public class, and a. java file can only have one common class, and the file name must be the same as the class.

By default , a class is declared as default and can be used by other classes in the same package.

Abstract, a class is declared as an abstract class, which can have abstract methods or No. Abstract classes can only be inherited and cannot be instantiated.

final, declaring a class as final (that is, a non-inheriting class), indicating that he cannot be inherited by another class.

External classes cannot use modifiers such as protected, private, and static, and internal classes can be used.

3. Member Variable modifiers

Permission modifiers: Private, default, Protected,public

Status modifier: static,final

4. Constructor Method Modifiers

Permission modifiers: Private, default, Protected,public

The most used is public.

5. Member Method modifiers

Permission modifiers: Private, default, Protected,public

Status modifiers: Static, Final

Abstract modifier: Abstract used to modify abstractions in abstract classes and interfaces

6. Some combination methods

Member variable: public static final

Member Methods:
* public static
* Public abstract
* Public Final

Modifiers in Java and their usage

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.