03.01.2015 Views

Complete set: Intro to C - Bill Buchanan

Complete set: Intro to C - Bill Buchanan

Complete set: Intro to C - Bill Buchanan

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

{<br />

static void Main()<br />

{<br />

Circuit cir = new Circuit();<br />

cir.r1=1000;<br />

cir.r2=1000;<br />

double res = cir.calcDifference();<br />

System.Console.WriteLine("Parallel Resistance is " + res);<br />

System.Console.ReadLine();<br />

}<br />

}<br />

Sample Run<br />

Parallel Resistance is 500<br />

It can be seen in Figure 8.3 that the method has been derived in the object.<br />

Figure 8.3: Derived classes<br />

duction <strong>to</strong> .NET<br />

<strong>Intro</strong><br />

8.3 Construc<strong>to</strong>rs<br />

A construc<strong>to</strong>r is a method which is au<strong>to</strong>matically called when the object of created.<br />

This is useful in initially <strong>set</strong>ting values <strong>to</strong> an object. It is defined within the class<br />

with the same name as class. For example <strong>to</strong> initialize a previous example if we had<br />

a class named Profile, then the construc<strong>to</strong>r within the class will also be named Profile,<br />

such as:<br />

public Profile(string c)<br />

{<br />

code=c;<br />

}<br />

public string Name<br />

{<br />

Agilent .NET Course: More Objects 8

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!