Beispiel #1
0
    static void Main(string[] args)
    {
        // A new instance of the Printer class is created
        // with the variable 'p'. The methods invoked
        // will display the strings from the base class
        // methods.
        Printer p = new Printer();

        p.show();
        p.print();

        // A new instance of the LaserJet class is created
        // with the local variable 'ls'. It will implement
        // the derived class' methods and their modified
        // strings.
        Printer ls = new LaserJet();

        ls.show();
        ls.print();

        // A new instance of the Officejet class is created
        // with the variable 'of'. It will invoke the show()
        // method from the LaserJet class but implement the
        // altered string of Officejet class for the print()
        // method.
        Printer of = new Officejet();

        of.show();
        of.print();
    }
    // Driver Code
    static void Main(string[] args)
    {
        Printer p = new Printer();

        p.show();
        p.print();

        Printer ls = new LaserJet();

        ls.show();
        ls.print();

        Printer of = new Officejet();

        of.show();
        of.print();
    }