Javase:3min to explain common modifiers __java

Source: Internet
Author: User

Today we'll take a look at the 7 most common modifiers, including permission modifiers (4): private,protected, default, public and state modifiers (2): Static,final and Abstract modifiers (1): abstract.

The following is a demo of the common classes and their compositions:
1. Class:

Class:
//private:illegal modifier for the class classpermissiontest only public, abstract & final are permitted
  
   //protected:illegal modifier for the class classpermissiontest; Only public, abstract & final are permitted
//public default OK

//static:illegal modifier for the class Classpermis Siontest; Only public, abstract & final are permitted
//final OK

//abstract OK public
class Classpermissiontest {
  

Conclusion:

Default, Public,final,abstract
Common: Public

2. Member variables:

	Member variable public
	int a = 1;
	protected int b = 2;
	int c = 3;
	private int d = 4;
	static int e = 5;
	final int f = 6;

Conclusion:
Private, default, protected,public,static,final
Common: Private

3. Construction Method:

	Construct Method-permission modifier
	//static:illegal modifier for the constructor in type classpermissiontest; only public, protected & P Rivate are permitted
	//final:illegal modifier for the constructor in type classpermissiontest; & private are permitted
	//abstract:illegal modifier for the constructor in type classpermissiontest; Protected & private are permitted
	private classpermissiontest () {}
	classpermissiontest (String s) {}
	protected classpermissiontest (int i) {} public
	classpermissiontest (Boolean b) {}

Conclusion:
Private, default, Protected,public
Common: Public

4. Member Methods:

	Member methods-permission modifiers, static, final, abstract all OK
	//abstract methods do not specify a body, parent class
	//abstract void Show ();
	void Show () {}

Conclusion:
Private, default, Protected,public,static,final,abstract
Common: Public

PS: When using abstract, the class must be an abstract class and the method cannot have a method body {}

Attached to the more common:
public static final int X = 10;
Public static/final/abstract Void Show () {}


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.