91. What will be the output of the following C# code?
interface i1
{
void f1();
}
interface i2 :i1
{
void f2();
}
public class maths :i2
{
public void f2()
{
Console.WriteLine("fun2");
}
public void f1()
{
Console.WriteLine("fun1");
}
}
class Program
{
static Void Main()
{
maths m = new maths();
m.f1();
m.f2();
}
}
interface i1
{
void f1();
}
interface i2 :i1
{
void f2();
}
public class maths :i2
{
public void f2()
{
Console.WriteLine("fun2");
}
public void f1()
{
Console.WriteLine("fun1");
}
}
class Program
{
static Void Main()
{
maths m = new maths();
m.f1();
m.f2();
}
}92. What will be the output of the following C# code?
namespace ConsoleApplication4
{
abstract class A
{
public int i;
public abstract void display();
}
class B: A
{
public int j;
public int sum;
public override void display()
{
sum = i + j;
Console.WriteLine(+i + "\n" + +j);
Console.WriteLine("sum is:" +sum);
}
}
class Program
{
static void Main(string[] args)
{
A obj = new B();
obj.i = 2;
B obj1 = new B();
obj1.j = 10;
obj.display();
Console.ReadLine();
}
}
}
namespace ConsoleApplication4
{
abstract class A
{
public int i;
public abstract void display();
}
class B: A
{
public int j;
public int sum;
public override void display()
{
sum = i + j;
Console.WriteLine(+i + "\n" + +j);
Console.WriteLine("sum is:" +sum);
}
}
class Program
{
static void Main(string[] args)
{
A obj = new B();
obj.i = 2;
B obj1 = new B();
obj1.j = 10;
obj.display();
Console.ReadLine();
}
}
}93. The process of defining two or more methods within the same class that have same name but different parameters list?
94. What will be the output of the following C# code?
class maths
{
public int length;
public int breadth;
public maths(int x, int y)
{
length = x;
breadth = y;
Console.WriteLine(x + y);
}
public maths(double x, int y)
{
length = (int)x;
breadth = y;
Console.WriteLine(x * y);
}
}
class Program
{
static void Main(string[] args)
{
maths m = new maths(20, 40);
maths k = new maths(12.0, 12);
Console.ReadLine();
}
}
class maths
{
public int length;
public int breadth;
public maths(int x, int y)
{
length = x;
breadth = y;
Console.WriteLine(x + y);
}
public maths(double x, int y)
{
length = (int)x;
breadth = y;
Console.WriteLine(x * y);
}
}
class Program
{
static void Main(string[] args)
{
maths m = new maths(20, 40);
maths k = new maths(12.0, 12);
Console.ReadLine();
}
}95. What will be the output of the following C# code?
static void Main(string[] args)
{
int x = 4 ,b = 2;
x -= b/= x * b;
Console.WriteLine(x + " " + b);
Console.ReadLine();
}
static void Main(string[] args)
{
int x = 4 ,b = 2;
x -= b/= x * b;
Console.WriteLine(x + " " + b);
Console.ReadLine();
}96. Which of these keywords is used to refer to member of base class from a sub class?
97. Which of the following functionality is facilitated by inheritance mechanism?
98. What is the process of defining a method in terms of itself, that is a method that calls itself?
99. Which keyword is used to declare a base class method while performing overriding of base class methods?
100. What will be the output of the following C# code?
class z
{
public string name1;
public string address;
public void show()
{
Console.WriteLine("{0} is in city{1}", name1, " ", address);
}
}
class Program
{
static void Main(string[] args)
{
z n = new z();
n.name1 = "harsh";
n.address = "new delhi";
n.show();
Console.ReadLine();
}
}
class z
{
public string name1;
public string address;
public void show()
{
Console.WriteLine("{0} is in city{1}", name1, " ", address);
}
}
class Program
{
static void Main(string[] args)
{
z n = new z();
n.name1 = "harsh";
n.address = "new delhi";
n.show();
Console.ReadLine();
}
}Read More Section(Classes and Objects in C Sharp)
Each Section contains maximum 100 MCQs question on Classes and Objects in C Sharp. To get more questions visit other sections.
