zoukankan      html  css  js  c++  java
  • C#认证考试试题汇编: 第二单元:1,11

    1、

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace Txst2_1
    {
    class Animal
    {
    private Boolean m_sex;
    private int m_age;
    public bool Sex
    {
    get { return m_sex; }
    set { m_sex = false; }
    }
    public int Age
    {
    get { return m_age; }
    set { m_age = value; }
    }
    public virtual string Introduce()
    {
    if (Sex == true)
    return "This is a male Animal";
    else
    return "This is a female Animal";
    }
    }
    class Dog:Animal
    {
    public Dog()
    {
    Sex = true;
    }
    public override string Introduce()
    {
    if (Sex == true)
    return "This is a male Dog";
    else
    return "This is a female Dog";
    }
    }
    class Cat:Animal
    {
    public override string Introduce()
    {
    if (Sex == true)
    return "This is a male Cat";
    else
    return "This is a female Cat";
    }
    }
    class Program
    {
    static void Main(string[] args)
    {
    Animal ani = new Animal();
    Console.WriteLine(ani.Introduce());
    Animal dog = new Dog();
    Console.WriteLine(dog.Introduce());
    Animal cat = new Cat();
    Console.WriteLine(cat.Introduce());
    Console.Read();
    }
    }
    }

     11、

    namespace Txst_2._1
    {
    class Animal
    {
    private Boolean m_sex;
    private string m_sound;
    public Animal()
    {
    m_sex = false;
    m_sound = "Howl...";
    }
    public bool Sex
    {
    get{ return m_sex; }
    set { m_sex = value; }

    }
    public string Sound
    {
    get { return m_sound; }
    set { m_sound = value; }
    }
    public virtual string Roar()
    {
    return "Animal" + m_sound;
    }
    }
    class Dog:Animal
    {
    public Dog()
    {
    Sex = true;
    Sound = "Wow...";
    }
    public override string Roar()
    {
    return "Dog:" + Sound;
    }
    }
    class Cat:Animal
    {
    public Cat()
    {
    Sound = "Miaow...";
    }
    public override string Roar()
    {
    return "Cat:" + Sound;
    }
    }
    class Cow:Animal
    {
    public Cow()
    {
    Sound = "Moo...";
    }
    public override string Roar()
    {
    return "Cow:" + Sound;
    }
    }
    class Program
    {
    static void Main(string[] args)
    {

    Animal animal;
    animal = new Dog();
    Console.WriteLine(animal.Roar());
    animal = new Cat();
    Console.WriteLine(animal.Roar());
    animal = new Cow();
    Console.WriteLine(animal.Roar());
    Console.Read();
    }
    }
    }

     
  • 相关阅读:
    FW : Unit of Measure related settings in SAP
    SAP PCA: 转移价格的确定
    SAP 关于贸易伙伴(Trading Partner)区分关联方/非关联方/子公司/第三方
    FSV tables in S/4 HANA OB58 , S_E38_98000088
    SAP Profit Center Table Data
    服务器搭建网站完整教程(宝塔面板+wordpress)
    运营
    undefined reference to `std::cout'等错误
    [c++][chromium]C++做与不做 C++ Dos and Don'ts
    [git]快速迁移git仓库
  • 原文地址:https://www.cnblogs.com/zjchang/p/7538319.html
Copyright © 2011-2022 走看看