Ok So Im writing a app which would pick the 'cheapest' plan for a consumer. While writing this I came across something puzzling to me. Why is it starting after the default constructor, the first CellPlan has three arguments passed too it and then the next one two and then one, why can the number be flipped around and be 1,2,3 or: 2,3,1 arguments (after the default constructor)?

//default constructor
        public CellPlan()
        { 
        }

        public CellPlan(string name, int zip, int minutes)
        {
            customerName = name;
            zipCode = zip;
            numberOfMinutes = minutes;
        } // end of CellPlan constructor

        public CellPlan(string name, int zip)
        {
            customerName = name;
            zipCode = zip;
        } // end of CellPlan constructor

        public CellPlan(int minutes)
        {
            numberOfMinutes = minutes;
        }

Thanks Again for all the help as always

Recommended Answers

This is called overloading, which you can also do with normal methods. This allows the object to be created with one,two, or three parameters. This allows the programmer to choose how to create the object. Below is a link with more information.

Jump to Post

All 2 Replies

thanks @jbrock31 !! helped me a lot!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.