C#學習笔记三

 

using  System;
public   class  test {
static string str_1 = "初始化一個值" ;
public test()
{
 str_1 
= "構造函數必須要實例化才能調用";
}

public static void Main() //Main 必須要聲明為static 只能返回int 或void
{
string str_1;
str_1 
= "另一個str_1";
Console.WriteLine(
"{0}",str_1); //值為:另一個str_1
Console.WriteLine("{0}",test.str_1); //這里調用的為類中的靜態變量 值為:初始化一個值
test t = new test();
Console.WriteLine(
"{0}",test.str_1); //因為已經實例化了一次,此處的值為:
//構造函數必須要實例化才能調用
test.str_1 = "還可另外賦值";
Console.WriteLine(
"{0}",test.str_1);//值為:還可另外賦值
son s = new son();
parent p 
= new son();
Console.WriteLine(s.i);
//值為:3
Console.WriteLine(p.i); //值為:1 和實例化的對像有關
}

public class parent{
public int i = 1;
int j = 2;
}

public class son:parent{
new public int i = 3;//用new 關鍵字隱藏父類中的相同變更,此處如不用public 則不行
}

interface Iclass
{
 
void My_Print();
}

}
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值