using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
public class Book
{
protected int isbn, price;
public int Isbn
{
get { return isbn; }
set { isbn = value; }
}
public int Price
{
get { return price; }
set { price = value; }
}
public Book(int isb)
{ isbn = isb; }
public Book()
{ }
}
class ComputerBook : Book
{
private string type;
public string Type
{
get { return type;}
set { type = value; }
}
}
class Program
{
static void Main(string[] args)
{
ComputerBook c1 = new ComputerBook();
c1.Isbn = 1;
c1.Price = 20;
c1.Type = "computer";
Console.WriteLine(c1.Type, c1.Isbn, c1.Price);
Console.ReadKey();
}
}
}
- 定义图书类Book。
- Book类中成员变量有isbn(书号)(字符串类型)、price(价格)(整型)两个保护类型变量。
- 编写一个带参数的构造函数为这两个变量赋值。
- 定义类computerBook,继承于Book类。computerBook类中有私有变量字符串型type(书的类型)
- 为类computerBook编程构造函数。
为什么输出只有type啊