Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            //			Object
            Being b=new Being();
            Console.WriteLine (b);

            //			Object attributes
            Person p1=new Person();
            p1.name="Jane";

            Person p2=new Person();
            p2.name="Beky";

            Console.WriteLine (p1.name);
            Console.WriteLine (p2.name);

            //			Methods
            Circle c=new Circle();
            c.SetRadius(5);
            Console.WriteLine (c.Area());

            //			Access modifiers
            Person2 p=new Person2();
            p.name="Jane";
            p.SetAge(17);
            Console.WriteLine ("{0} is {1} years old",p.name,p.GetAge());
            //			another example of access modifiers
            Derived d=new Derived();
            d.info();

            //			The constructor
            new Being2();
            new Being2("Tom");
            //			another example of constructor
            string name="Lenka";
            DateTime born=new DateTime(1990,3,5);

            MyFriend f=new MyFriend(name,born);
            f.info();

            //			Constructor chaining
            new Circle2(5);
            new Circle2();

            //			Class constants
            Console.WriteLine (Math.PI);
            Console.WriteLine (Math.radius);

            //			The ToString() method
            Being3 be=new Being3();
            object ob=new object();
            Console.WriteLine (ob.ToString());
            Console.WriteLine (be.ToString());
            Console.WriteLine (be);
            //			Note that when we call the Console.WriteLine() method
            //			with an object as a parameter,
            //			the ToString() is being called.

            //			Inheritance
            new Human();
            //			another example
            Console.WriteLine ();
            new Human2();
            Dog dog=new Dog();
            dog.GetCount();
            //			another example2
            Console.WriteLine ();
            Circle3 x=new Circle3(2,4,6);
            Console.WriteLine (x);

            //			Abstract classes and methods
            Console.WriteLine ();
            Circle4 z=new Circle4(12,45,22);
            Console.WriteLine (z);//show the ToString() method, defaultly
            Console.WriteLine ("Area of circle: {0}",z.Area());
            Console.WriteLine (z.GetCoordinates());
        }