using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace check
{
class Baseclass
{
//public Baseclass()
//{
// Console.WriteLine("Now i am in default constructor");
//}
public Baseclass(int a)
{
Console.WriteLine("Value of Baseclass a is : {0}", a + 10);
}
}
class Derivedclass:Baseclass
{
//public Derivedclass()
//{
//}
public Derivedclass(int a)
: base(a)
{
Console.WriteLine("Value of Derived Class a is : {0}", a);
}
}
class Program
{
static void Main(string[] args)
{
Derivedclass d = new Derivedclass(5);
Console.ReadLine();
}
}
}
--Now this gives me output
Value of Baseclass a is : 15
Value of Derivedclass a is :5
-----------------------------------------
case 2 :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace check
{
class Baseclass
{
//public Baseclass()
//{
// Console.WriteLine("Now i am in default constructor");
//}
public Baseclass(int a)
{
Console.WriteLine("Value of Baseclass a is : {0}", a + 10);
}
}
class Derivedclass:Baseclass
{
public Derivedclass()
{
}
public Derivedclass(int a)
: base(a)
{
Console.WriteLine("Value of Derived Class a is : {0}", a);
}
}
class Program
{
static void Main(string[] args)
{
Derivedclass d = new Derivedclass(5);
Console.ReadLine();
}
}
}
--Now this gives me error
'check.Baseclass' does not contain a constructor that takes '0' arguments
-------------------------------------------------------------------------------
case 3:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace check
{
class Baseclass
{
//public Baseclass()
//{
// Console.WriteLine("Now i am in default constructor");
//}
//public Baseclass(int a)
//{
// Console.WriteLine("Value of Baseclass a is : {0}", a + 10);
//}
}
class Derivedclass:Baseclass
{
public Derivedclass()
{
}
public Derivedclass(int a)
{
Console.WriteLine("Value of Derived Class a is : {0}", a);
}
}
class Program
{
static void Main(string[] args)
{
Derivedclass d = new Derivedclass(5);
Console.ReadLine();
}
}
}
Now this gives me output:
Value of Derived class a is : 5
--------------------------------------
case 4:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace check
{
class Baseclass
{
//public Baseclass()
//{
// Console.WriteLine("Now i am in default constructor");
//}
public Baseclass(int a)
{
Console.WriteLine("Value of Baseclass a is : {0}", a + 10);
}
}
class Derivedclass:Baseclass
{
//public Derivedclass()
//{
// Console.WriteLine("anurag");
//}
public Derivedclass(int a)
{
Console.WriteLine("Value of Derived Class a is : {0}", a);
}
}
class Program
{
static void Main(string[] args)
{
Derivedclass d = new Derivedclass(5);
Console.ReadLine();
}
}
}
o/p
This gives me error
--------------------------------------
1)
a)if we are creating parametrized constructor of baseclass.
b)And if we try to create default constructor of derived class
c)And if no default constructor of base class
d)creating object of derived class
it is showing error.
2)
a)If no constructor of baseclass is there
b)If default constructor of derived class is there
c)creating a object of derived class.
No comments:
Post a Comment