O'Reilly logo

Microsoft® Visual C#® 2008 Step by Step by John Sharp

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Initializing Objects by Using Properties

In Chapter 7, Chapter 7, you learned how to define constructors to initialize an object. An object can have multiple constructors, and you can define constructors with varying parameters to initialize different elements in an object. For example, you could define a class that models a triangle like this:

public class Triangle { private int side1Length; private int side2Length; private int side3Length; // default constructor - default values for all sides public Triangle() { this.side1Length = this.side2Length = this.side3Length = 10; } // specify length for side1Length, default values for the others public Triangle(int length1) { this.side1Length = length1; this.side2Length = this.side3Length = 10; } // ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required