0% found this document useful (0 votes)
47 views3 pages

C# Ques

The document contains 11 multiple choice questions about C# programming concepts such as classes, inheritance, access modifiers, methods, and control flow statements. It tests knowledge of class member access using '.', abstract classes and methods, method overloading, output of code samples, and syntax for common programming structures like if/else, for loops, and switch statements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views3 pages

C# Ques

The document contains 11 multiple choice questions about C# programming concepts such as classes, inheritance, access modifiers, methods, and control flow statements. It tests knowledge of class member access using '.', abstract classes and methods, method overloading, output of code samples, and syntax for common programming structures like if/else, for loops, and switch statements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

1. The operator used to access member function of a class?

a) :
b) ::
c) .
d) #

2.The data members of a class by default are?


a) protected, public
b) private, public
c) private
d) public

3.What will be the output of the following C# code?

class test
{
public void print()
{
Console.WriteLine("Csharp:");
}
}
class Program
{
static void Main(string[] args)
{
test t;
t.print();
Console.ReadLine();
}
}

a) Syntax error as t is unassigned variable which is never used


b) Code runs successfully prints nothing
c) Code runs and prints “Csharp”
d) None of the mentioned

4. A type of class which does not have its own objects but acts as a base class for
its subclass is known as?
a) Static class
b) Abstract class
c) Sealed class
d) None of the mentioned

5. Choose the correct statements among the following:


a) An abstract method does not have implementation
b) An abstract method can take either static or virtual modifiers
c) An abstract method can be declared only in abstract class
d) All of the mentioned

6.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();
}
}
}

a)2, 10
12

b)0, 10
10

c)2, 0
2

d)0, 0
0

7.Can the method add() be overloaded in the following ways in C#?

public int add() { }


public float add(){ }
a) True
b) False
c)Compiler Error
d)Non of the Above

8.What will be the output of the following C# code?

using System;

namespace MyApplication {
class Program {
static void Main(string[] args) {
bool x = true;
Console.Write(Convert.ToString(x));
}
}
}
A) True
B) true
C) False
D) false

8. Write a factorial Program. Example


Input : Enter any Number: 6
Output: Factorial of 6 is: 720

9.What will be the output of the following C# code?

using System;

class Program {
static void Main(string[] args) {
int i = 2;
int j = 10 / 4;

if (i == j) {
Console.WriteLine("True");
} else {
Console.WriteLine("False");
}
}
}
A) True
B) False
C) Error
D) None

10.Which access specifier should be used for Main() method in C#?

A) private
B) public
C) protected
D) internal

11. Write Syntax for the following:


a.If-else statement
b.multiple If Statement
c.Switch Case
d.For loop
e.Foreach

You might also like