.Net > Input > Beginner Next/Skip this question

What would be the output of following code snippet?

using System;

class Perl
{
    public Perl()
    {
        // Call instance method with this.
        this.B();
    }

    int _a; // Instance field

    public void B() // Parameterless instance method
    {
        // Increment instance field without "this".
        _a++;
        // Increment instance field with "this".
        this._a++;
        // Read instance field with "this".
        Console.WriteLine("B called: " + this._a);
    }
}

class Program
{
    static void Main()
    {
        // Create a new instance of the type Perl.
        // ... The constructor calls method B.
        // ... Then we call method B again.
        Perl perl = new Perl();
        perl.B();
    }
}
Answers :
Explaination :
social share share on facebook share on twitter share on google plus share on linkedin
Add Comments :

Login

Register

Next Question