What will be the output of the following C# code?
class z
{
public int X;
public int Y;
public const int c1 = 5;
public const int c2 = c1 * 25;
public void set(int a, int b)
{
X = a;
Y = b;
}
}
class Program
{
static void Main(string[] args)
{
z s = new z();
s.set(10, 20);
Console.WriteLine(s.X + " " + s.Y);
Console.WriteLine(z.c1 + " " + z.c2);
Console.ReadLine();
}
}A. 10 20
5 25
B. 20 10
25 5
C. 10 20
5 125
D. 20 10
125 5
Select an option to see the answer and solution.
The capability of an object in Csharp to take number of different forms and hence display behaviour as according is known as . . . . . . . .
A. Encapsulation
B. Polymorphism
C. Abstraction
D. None of the mentioned
Select an option to see the answer and solution.
Which C# statement should be added in function a() of class y to get output "i love csharp"?
class x
{
public void a()
{
console.write("bye");
}
}
class y : x
{
public void a()
{
/* add statement here */
console.writeline(" i love csharp ");
}
}
class program
{
static void main(string[] args)
{
y obj = new obj();
obj.a();
}
}A. x.a();
B. a();
C. base.a();
D. x::a();
Select an option to see the answer and solution.
What will be the output of the following C# code?
static void Main(string[] args)
{
int x = 8;
int b = 16;
int C = 64;
x /= b /= C /= x;
Console.WriteLine(x + " " + b+ " " +C);
Console.ReadLine();
}A. 8 2 4
B. 2 4 8
C. 4 2 8
D. Compile time error
Select an option to see the answer and solution.
What is the most specified using class declaration?
A. type
B. scope
C. type & scope
D. none of the mentioned
Select an option to see the answer and solution.
Given class sample is inherited by class sample 1. Which are the correct statements about construction of object of class sample?
A. While creating the object firstly the constructor of class sample will be called followed by constructor of class sample 1
B. The constructor of only sample class will be called
C. While creating the object firstly constructor of class sample 1 will be called followed by constructor of class sample
D. The order of calling constructors depend on whether constructors in class sample and sample 1 are private or public
Select an option to see the answer and solution.
What will be the output of the following C# code?
interface i1
{
void fun();
}
interface i2
{
void fun();
}
public class maths :i1, i2
{
void i1.fun()
{
Console.WriteLine("i1.fun");
}
void i2.fun()
{
Console.WriteLine("i2.fun");
}
}
class Program
{
static void Main(string[] args)
{
Sample obj = new Sample();
i1 i = (i1) obj;
i.fun();
i2 ii = (i2) obj;
ii.fun();
}
}A. i1.fun
B. i2.fun
i1.fun
C. 0
D. i1.fun
i2.fun
Select an option to see the answer and solution.
Arrange the following overloaded operators in increasing order of precedence?
%, <<, &, /, +A. '%' < '<<' < '+' < '-' < '&' < '/'
B. '<<' < '&' < '%' < '-' < '/' < '+'
C. '&' < '-' <'%' < '<<' < '/' < '+'
D. '/' < '-' < '%' < '+' < '<<' < '&'
Select an option to see the answer and solution.
What will be the output of the following C# code?
class maths
{
public maths()
{
Console.WriteLine("constructor 1 :");
}
public maths(int x)
{
int p = 2;
int u;
u = p + x;
Console.WriteLine("constructor 2: " +u);
}
}
class Program
{
static void Main(string[] args)
{
maths k = new maths(4);
maths t = new maths();
Console.ReadLine();
}
}A. constructor 1:
constructor 2: 6
B. constructor 2: 6
constructor 2: 6
C. constructor 2: 6
constructor 1:
D. none of the mentioned
Select an option to see the answer and solution.
What will be the output of the following C# code?
enum colors
{
red,
black,
pink
}
colors s = colors.black;
type t;
t = c.GetType();
string[] str;
str = Enum.GetNames(t);
Console.WriteLine(str[0]);Select an option to see the answer and solution.
What will be the output of the following C# code?
static void Main(string[] args)
{
m();
Console.ReadLine();
}
static void m()
{
Console.WriteLine("HI");
m();
}A. HI HI HI
B. HI
C. Stack overflow exception
D. Compile time error
Select an option to see the answer and solution.
When does a structure variable get destroyed?
A. When no reference refers to it, it will get garbage collected
B. Depends on whether it is created using new or without new operator
C. As variable goes out of the scope
D. Depends on either we free its memory using free() or delete()
Select an option to see the answer and solution.
Select wrong statement about destructor in C#?
A. A class can have one destructor only
B. Destructors cannot be inherited or overloaded
C. Destructors can have modifiers or parameters
D. All of the mentioned
Select an option to see the answer and solution.
What will be the Correct statement of the following C# code?
public class maths
{
public int x;
public virtual void a()
{
}
}
public class subject : maths
{
new public void a()
{
}
}A. The subject class version of a() method gets called using sample class reference which holds subject class object
B. subject class hides a() method of base class
C. The code replaces the subject class version of a() with its math class version
D. None of the mentioned
Select an option to see the answer and solution.
Which of the following statements correctly define about the implementation of interface?
A. The calls to implementation of interface methods are routed through a method table
B. A class which implements an interface can explicitly implement members of that interface
C. One interface can be implemented in another interface
D. None of the mentioned
Select an option to see the answer and solution.
What will be the output of the following C# code?
{
struct abc
{
public int i;
}
class Program
{
static void Main(string[] args)
{
sample a = new sample();
a.i = 10;
fun(ref a);
Console.WriteLine(a.i);
}
public static voidn fun(ref sample x)
{
x.i = 20;
Console.WriteLine(x.i);
}
}
}A. 10
10
B. 20
10
C. 10
20
D. 20
20
Select an option to see the answer and solution.
What will be the output of the following C# code?
class maths
{
int fact(int n)
{
int result;
if (n == 1)
return 1;
result = fact(n - 1) * n;
return result;
}
}
class Output
{
static void main(String args[])
{
maths obj = new maths() ;
Console.WriteLine(obj.fact(1));
}
}Select an option to see the answer and solution.
Choose the correct statement among the following which supports the fact that C# does not allow the creation of empty structures?
A. C#.NET supports creation of abstract user-defined data types using structures
B. By having empty structures, it would mean that the new data types have no data associated with, which does not make any sense in C#.NET
C. Basic reason to create structures is the inability to represent real life objects using standard data types offered by the language
D. All of the mentioned
Select an option to see the answer and solution.
Correct method to define + operator is?
A. public sample operator +(int a, int b)
B. public abstract operator +(int a, int b)
C. public static sample operator +(int a, int b)
D. public abstract sample operator +(int a, int b)
Select an option to see the answer and solution.
What will be the Correct statement in the following C# code?
interface a1
{
void f1();
void f2();
}
class a :a1
{
private int i;
void a1.f1()
{
}
}A. Class a could not have an instance data
B. Class a is an abstract class
C. Class a fully implements the interface a1
D. None of the mentioned
Select an option to see the answer and solution.