C # object-oriented class,

Source: Internet
Author: User

C # object-oriented class,

1 for (int I = 0; I <10; I ++) 2 {3 student. B ++; // If the static field is not assigned a value, the default value is 1; 4 new student (). a ++; // After referencing the definition of a type variable, you must use the new keyword to create an object before using the 5 Console. writeLine (student. B + "" + new student (). a); 6} 7 Console. writeLine (new student (). shu (); 8 9
10 11 class student12 {13 public int a; 14 public static int B; // static members do not initialize with the object creation. Class static method can only access static field 15 public int hanshu () 16 {17 return a + B; // The class field can be directly called by the instance method 18} 19 public int shu () 20 {21 return hanshu (); // common methods in the same class can call each other 22} 23}

 

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.