示例#1
0
        static void Main(string[] args)
        {
            Conta            cc    = new Conta(1004, "Fulano", 0.0);
            ContaEmpresarial ccEmp = new ContaEmpresarial(1008, "Circlano", 0.0, 500.00);

            //UPCASTING
            Conta cc1 = ccEmp;
            Conta cc2 = new ContaEmpresarial(1009, "Juca", 0.0, 600);
            Conta cc3 = new ContaPoupanca(1010, "Sr.Juca", 0.0, 0.01);

            //DOWNCASTING
            //ContaEmpresarial c1 = cc2;
            ContaEmpresarial ce1 = (ContaEmpresarial)cc2;

            ce1.Emprestimo(200.00);

            //ContaEmpresarial ccEmp2 = (ContaEmpresarial)cc3;
            if (cc3 is ContaEmpresarial)
            {
                ContaEmpresarial conta = (ContaEmpresarial)cc3;
                conta.Emprestimo(200);
                Console.WriteLine("Emprestimo");
            }

            if (cc3 is ContaPoupanca)
            {
                //ContaPoupanca conta = (ContaPoupanca)cc3;
                ContaPoupanca conta = cc3 as ContaPoupanca;
                conta.AtualizarSaldo();
                Console.WriteLine("AtualizarSaldo");
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            Conta c = new Conta(12131, "Bruno Vernay", 1250.50);

            Console.WriteLine(c.Saldo.ToString());
            c.Deposito(1000);
            Console.WriteLine(c.Saldo.ToString());
            c.Retirada(1000);
            Console.WriteLine(c.Saldo.ToString());

            ContaEmpresarial ce = new ContaEmpresarial(12131, "Bruno Vernay", 5000.0, 1000);

            Console.WriteLine(ce.Saldo.ToString());
            ce.Deposito(1000);
            Console.WriteLine(ce.Saldo.ToString());
            ce.Retirada(1000);
            Console.WriteLine(ce.Saldo.ToString());
            ce.LimiteEmprestimo = 1000;
            ce.Emprestimo(2000);
            Console.WriteLine(ce.Saldo.ToString());
            ce.Emprestimo(500);
            Console.WriteLine(ce.Saldo.ToString());
        }