1. Could we overload an instance constructor?
2. Does constructors have a return type
3. Could we inherit constructor?
4. When is a destructor invoked?
5. How are destructors invoked?
Wednesday, January 16, 2008
Tuesday, January 15, 2008
Question on exception / try - catch block
Question:
What will be the output for follwing code
try
{
Console.WriteLine("Before Exception");
throw new Exception("Raising exception");
Console.WriteLine("After Exception");
}
catch(Exception e)
{
Console.WriteLine("Inside Catch");
}
finally
{
Console.WriteLine("Inside Finally");
}
Console.WriteLine("Outside Try");
Answer:
Before Exception
Inside Catch
Inside Finally
Outside Try
What will be the output for follwing code
try
{
Console.WriteLine("Before Exception");
throw new Exception("Raising exception");
Console.WriteLine("After Exception");
}
catch(Exception e)
{
Console.WriteLine("Inside Catch");
}
finally
{
Console.WriteLine("Inside Finally");
}
Console.WriteLine("Outside Try");
Answer:
Before Exception
Inside Catch
Inside Finally
Outside Try
Friday, January 11, 2008
.NET basics revisited......continued
Now question below is from a written test / interview
Question:
public void MergeSort(List list, int low, int high)
{
int temp;
if (low == high)
{
return;
}
if (high - low == 1)
{
if (list[low] > list[high])
{
temp = list[low];
list[low] = list[high];
list[high] = temp;
}
}
else
{
int mid = high + low / 2;
MergeSort(list, low, mid);
MergeSort(list, mid + 1, high);
}
}
a. run time exception
b. Will completely sort the list
c. Will partially sort the list
Answer: Stackoverflow exception, recursive call is going for an infinite loop.....
also please do comment if any other answers
Question:
public void MergeSort(List list, int low, int high)
{
int temp;
if (low == high)
{
return;
}
if (high - low == 1)
{
if (list[low] > list[high])
{
temp = list[low];
list[low] = list[high];
list[high] = temp;
}
}
else
{
int mid = high + low / 2;
MergeSort(list, low, mid);
MergeSort(list, mid + 1, high);
}
}
a. run time exception
b. Will completely sort the list
c. Will partially sort the list
Answer: Stackoverflow exception, recursive call is going for an infinite loop.....
also please do comment if any other answers
Thursday, January 10, 2008
.NET basics revisited
I am on 'bench' these days.....well if thats not in your dictionary - 'its that condition of software engineer when he/she is not assigned to any projects / tasks'.
So thought of checking out tips, questions, tweaks, forums,interview questions etc in .NET....my next posts will be ones i have come across...so look out :)
Question: Which one among the following is illegal
a. Base b = new Derived();
b. Dervied b = new Base();
Where Derived is class inherited from Base...
Answer: b, now u can try and tell me
Question :
class A
{
public virtual void f()
{
Console.WriteLine("A.F");
}
}
class B : A
{
public override void f()
{
Console.WriteLine("B.F");
}
}
class C : B
{
new public virtual void f()
{
Console.WriteLine("C.F");
}
}
class D : C
{
public override void f()
{
Console.WriteLine("D.F");
}
}
class Program
{
static void Main(string[] args)
{
D d = new D();
A a = d;
B b = d;
C c = d;
a.f();
b.f();
c.f();
d.f();
}
}
What will this print
Answer: B.F B.F D.F D.F
If derived class overrides a method base class, objects of the derived class will call that method rather than the base class method.
So thought of checking out tips, questions, tweaks, forums,interview questions etc in .NET....my next posts will be ones i have come across...so look out :)
Question: Which one among the following is illegal
a. Base b = new Derived();
b. Dervied b = new Base();
Where Derived is class inherited from Base...
Answer: b, now u can try and tell me
Question :
class A
{
public virtual void f()
{
Console.WriteLine("A.F");
}
}
class B : A
{
public override void f()
{
Console.WriteLine("B.F");
}
}
class C : B
{
new public virtual void f()
{
Console.WriteLine("C.F");
}
}
class D : C
{
public override void f()
{
Console.WriteLine("D.F");
}
}
class Program
{
static void Main(string[] args)
{
D d = new D();
A a = d;
B b = d;
C c = d;
a.f();
b.f();
c.f();
d.f();
}
}
What will this print
Answer: B.F B.F D.F D.F
If derived class overrides a method base class, objects of the derived class will call that method rather than the base class method.
Subscribe to:
Posts (Atom)