STATC static calls differ in C # in Java, static constructors for C # and construction code blocks in Java, static code blocks

Source: Internet
Author: User
Tags modifiers

Differences between 1.java and C # static member invocation

Static, which is a shared resource, is created when the class is loaded.

Java can be invoked through an instance, or by a class name. member name, but it is generally preferable to use the class name. Member this way, because static members belong to the class, not to specific objects

C # can only be called by the class name. Member, and cannot be

To invoke with an instance


2.c# Static constructors and construction code blocks in Java, static code blocks

Features of C # static constructors:
1) Static constructors do not need to be called manually, the system automatically calls
2) A static constructor is executed when a static member is first used or initialized to an object, and takes precedence over the constructor or the invocation of a static member.
3) Static constructors cannot add access modifiers and parameters, default to Private
Grammar:
Static class name ()
{
Code
}

Java Static code block features:
1) Static code block does not need to be called manually, the system automatically calls
2) A static code block executes at the first time the class is loaded and executes only once, so the precedence constructor executes (constructor: used when instantiating)
3) Static code block cannot add access modifiers and parameters


Grammar:
static{
Code
}

Java Construction code block features:
1) Initialize the object. The object runs as soon as it is established and takes precedence over the constructor.

2) Difference from constructor function

--the difference between constructing a block of code and constructing a code block is to initialize all objects uniformly, and constructors to initialize the corresponding objects.

--The function of constructing code blocks: It is to extract the public information from all the construction methods.

For example a child born unified cry


3) Syntax:
{
Code
}






STATC static calls differ in C # in Java, static constructors for C # and construction code blocks in Java, static code blocks

Related Article

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.