zoukankan      html  css  js  c++  java
  • 类的测试

    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace ConsoleApplication1
    {
      class myclass
        {
            private int intStudentId;//定义字段(私有成员)
            public int _intStudentId //定义属性
            {
                get { return intStudentId; }
                set
                {
                    if (value< 0)
                    {
                        intStudentId = -value;
                    }
                    else  intStudentId = value;
                }

            }
            public myclass(string strName)//带参数的构造函数
            {

                Console.Write(strName);
            }
            public myclass()//默认构造函数
            {
                Console.Write("Hello!");
           
           
            }
            public static string GetNation (string strNation)//公有的静态方法(通过类可以访问,不同实例化)

            {

                return strNation;
             }


         

        
        }

        class  TestClass
        {
            static void Main(string[] args)
            {

                Console.Write("My Nation is:" + myclass.GetNation("China"));
                Console.Write("\n");
                myclass annclass = new myclass();
                Console.Write("\n");
                myclass lzlClass = new myclass("lzl");
                Console.Write("\n");
                lzlClass._intStudentId = -100;
                Console.Write(lzlClass._intStudentId);
                Console.ReadLine();
            } 
        }

         


    }

  • 相关阅读:
    【转】SVN与Git比较
    我遇到了Hibernate异常
    使用 Eclipse 远程调试 Java 应用程序
    linux显示桌面快捷键设置
    Ubuntu共享WiFi(AP)给Android方法
    用zd1211+Ubuntu 10.04实现的AP
    Ubuntu开机自动禁用无线网络
    戴尔大力宣传Ubuntu 对比与Windows的差异
    【SSH进阶之路】Spring的AOP逐层深入——采用注解完成AOP(七)
    【SSH进阶之路】Spring的AOP逐层深入——AOP的基本原理(六)
  • 原文地址:https://www.cnblogs.com/liuzhengliang/p/1311252.html
Copyright © 2011-2022 走看看