Java variable declaration, assignment problem

Source: Internet
Author: User
Review the following code to write a method of modification that allows the program to perform correctly
1.public class MyClass {
2. Static String S1;
3. String S2;
4. public static void Main (String args[]) {
5. String S3;
6. System.out.println ("S1 =" + S1);
7. System.out.println ("s2 =" + s2);
8. System.out.println ("s3 =" + S3);
9.}

10.}

Resolve: Delete line 8th or change line 5th to string s3 = "";

This problem involves the declaration assignment of variables, summarized as follows:

Instance variable declarations can be uninitialized and the system is automatically initialized to 0 or null;

Local variables must first be assigned before they are used;

The local variable is the same as the instance variable and the local variable.

The local variable allows the same name within its scope;

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.