프로그래밍/C#
객체지향 - 3
beautifulhill
2020. 3. 20. 17:19
상속
private으로 선언된 멤버는 상속 불가능
protected 사용시 자식클래스가 부모의 멤버에 접근 가능
추상클래스는 다중상속 불가능
using System;
using Product;
namespace Example
{
class Program
{
static void Main(string [] args)
{
Idol idol = new Idol();
idol.Numb = 0;
idol.Numb = 0;
idol.Numb = 0;
bool getPrize = idol.Prize();
if(getPrize)
Console.WriteLine("경품받기");
}
}
}
namespace Product {
class Album
{
private int numb;
private string singer;
private string album_name;
public Album()
{
}
public int Numb
{
get { return numb; }
set { numb += 1; }
}
}
class Idol : Album
{
public bool Prize()
{
if (Numb > 2)
return true;
else
return false;
}
}
}
protected 사용
using System;
using Product;
namespace Example
{
class Program
{
static void Main(string [] args)
{
Idol idol = new Idol();
idol.Numb = 0;
idol.Numb = 0;
idol.Numb = 0;
bool getPrize = idol.Prize();
if(getPrize)
Console.WriteLine("경품받기");
}
}
}
namespace Product {
class Album
{
protected int numb;
private string singer;
private string album_name;
public Album()
{
}
public int Numb
{
get { return numb; }
set { numb += 1; }
}
}
class Idol : Album
{
public bool Prize()
{
if (numb > 2)
return true;
else
return false;
}
}
}