1. If a class inheriting an abstract class does not define all of its functions then it is known as?
2. What will be the output of the following C# code?
namespace ConsoleApplication4
{
class A
{
public int i;
public void display()
{
Console.WriteLine(i);
}
}
class B: A
{
public int j;
public void display()
{
Console.WriteLine(j);
}
}
class Program
{
static void Main(string[] args)
{
B obj = new B();
obj.j = 1;
obj.i = 8;
obj.display();
Console.ReadLine();
}
}
}
namespace ConsoleApplication4
{
class A
{
public int i;
public void display()
{
Console.WriteLine(i);
}
}
class B: A
{
public int j;
public void display()
{
Console.WriteLine(j);
}
}
class Program
{
static void Main(string[] args)
{
B obj = new B();
obj.j = 1;
obj.i = 8;
obj.display();
Console.ReadLine();
}
}
}3. What will be the output of the following C# code?
enum per
{
a,
b,
c,
d,
}
per.a = 10;
Console.writeline(per.b);
enum per
{
a,
b,
c,
d,
}
per.a = 10;
Console.writeline(per.b);4. What will be the output of the following C# code?
class sample
{
public sample()
{
Console.WriteLine("THIS IS BASE CLASS constructor");
}
}
public class sample1 : sample
{
}
class Program
{
static void Main(string[] args)
{
sample1 obj = new sample1();
Console.ReadLine();
}
}
class sample
{
public sample()
{
Console.WriteLine("THIS IS BASE CLASS constructor");
}
}
public class sample1 : sample
{
}
class Program
{
static void Main(string[] args)
{
sample1 obj = new sample1();
Console.ReadLine();
}
}5. Select the wrong statements among the following?
6. What will be the output of the following C# code?
class maths
{
public int x;
public double y;
public int add(int a, int b)
{
x = a + b;
return x;
}
public int add(double c, double d)
{
y = c + d;
return (int)y;
}
public maths()
{
this.x = 0;
this.y = 0;
}
}
class Program
{
static void Main(string[] args)
{
maths obj = new maths();
int a = 4;
double b = 3.5;
obj.add(a, a);
obj.add(b, b);
Console.WriteLine(obj.x + " " + obj.y);
Console.ReadLine();
}
}
class maths
{
public int x;
public double y;
public int add(int a, int b)
{
x = a + b;
return x;
}
public int add(double c, double d)
{
y = c + d;
return (int)y;
}
public maths()
{
this.x = 0;
this.y = 0;
}
}
class Program
{
static void Main(string[] args)
{
maths obj = new maths();
int a = 4;
double b = 3.5;
obj.add(a, a);
obj.add(b, b);
Console.WriteLine(obj.x + " " + obj.y);
Console.ReadLine();
}
}7. What will be the Correct statement in the following C# code?
interface a1
{
void f1();
int f2();
}
class a :a1
{
void f1()
{
}
int a1.f2()
{
}
}
interface a1
{
void f1();
int f2();
}
class a :a1
{
void f1()
{
}
int a1.f2()
{
}
}8. Which of the following statements are correct in nature?
9. Which form of inheritance is not supported directly by C# .NET?
10. What will be the output of the following C# code snippet?
class maths
{
public int fact(int n)
{
int result;
if (n == 2)
return 1;
result = fact(n - 1) * n;
return result;
}
}
class Program
{
static void Main(string[] args)
{
maths obj = new maths();
Console.WriteLine(obj.fact(4));
Console.ReadLine();
}
}
class maths
{
public int fact(int n)
{
int result;
if (n == 2)
return 1;
result = fact(n - 1) * n;
return result;
}
}
class Program
{
static void Main(string[] args)
{
maths obj = new maths();
Console.WriteLine(obj.fact(4));
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.
