Wednesday, 28 March 2012

class related questions

Q1   Give The Output of this program-


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace
{
ConsoleApplication1
public class aa
{
string name;
int age;
public aa(string name, int age)
{
name = name;
age = age;

}
static void Main(string[] args)
{
aa a = new aa("mukesh", 26);
console.writeline("name="+a.name);
console.writeline("name="+a.age);
}
}

 

answer - name=...

         age=0
if you want mukesh and age also.then this program will call like this way



using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace
{
ConsoleApplication1

public class aa
{ string name;int age;
public aa(string name, int age)
{
{
name = name;
age = age;

Console.WriteLine(name); //this will work in local label means give output in constructor only
Console.WriteLine(age); //this will work in local label means give output in constructor only
Console.ReadLine();
}
static void Main(string[] args)

{
aa a = new aa("mukesh", 26);
}
}

No comments:

Post a Comment