나는 다음 한 코드왜 최종 출력은 0이다 : OOPS 샘플
using System;
namespace xyzApp
{
class Program
{
public static void Main(string[] args)
{
Test1Class t = new Test1Class();
t.Add(4);
t.Add(11.1);
t.showValue();
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
class TestClass{
protected int sum =0;
public void Add(int x)
{
sum+=x;
}
public void showValue()
{
Console.WriteLine(" the sum is : {0}",sum);
}
}
class Test1Class :TestClass
{
double sum ;
public void Add(double x)
{
sum+=x;
Console.WriteLine(" the sum is : {0}",sum);
}
}
}
출력은
the sum is : 4
the sum is : 15.1
the sum is : 0
Press any key to continue . . .
최종 출력이 나는 등의 최종 출력을 얻을 수있는 방법 0, 왜
누군가가, 설명 할 수 파생 클래스에서 printValue 메서드를 만들지 않고 15.1.
나는 언어와 언어의 차이점을 알고 싶다. 감사
Testclass의 sum 변수도 Double이어야합니다. 그렇지 않으면 Test1class 메서드에서 "double을 int로 변환 할 수 없습니다"오류가 발생합니다. – Nanda
@nanda - 사실, 다른 데이터 유형을 알지 못했습니다 ... 편집 ... – froadie
감사합니다. 파생 클래스에서 기본 클래스 멤버의 데이터 유형을 구입할 수있는 방법이 있습니까? – Sharique