C# Test

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10
At a glance
Powered by AI
The key takeaways from the document are that it discusses concepts related to C# programming such as classes, inheritance, properties, operators, exceptions etc.

The two types of threads mentioned are foreground and background threads.

The correct way to overload the + operator is using public static operator + (sample a, sample b).

1. CLR is the .Net equivalent of _____.

A. Java Virtual machine


B. Common Language Runtime
C. Common Type System
D. Common Language Specification

2. Abstract class contains _____.

A. Abstract methods
B. Non Abstract methods
C. Both
D. None

3. The default scope for the members of an interface is _____.

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

4. Which of the following statements is incorrect about delegate?

A. Delegates are reference types.


B. Delegates are object-oriented.
C. Delegates are type-safe.
D. Only one can be called using a delegate.

5. The space required for structure variables is allocated on the stack.

A. True
B. False
C. Maybe
D. Can’t say

6. Which of the following is incorrect about constructors?

A. Defining of constructors can be implicit or explicit.


B. The calling of constructors is explicit.
C. Implicit constructors can be parameterized or parameterless.

1
D. Explicit constructors can be parameterized or parameterless.

7. Reference is a ___.

A. Copy of class which leads to memory allocation.


B. Copy of class that is not initialized.
C. Pre-defined data type.
D. Copy of class creating by an existing instance.

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

A. protected, public
B. private, public
C. private
D. public

9. What is the value returned by function compareTo( ) if the invoking string is less
than the string compared?

A. Zero
B. A value of less than zero
C. A value greater than zero
D. None of the mentioned

10.  The correct way to overload +operator?

A. public sample operator +  (sample a, sample b)


B. public abstract operator +  (sample a, sample b)
C. public static operator +  (sample a, sample b)
D. all of the mentioned above

11. Select the two types of threads mentioned in the concept of multithreading?

A. Foreground
B. Background
C. Only foreground
D. Both foreground and background

12. Choose the wrong statement about properties used in C#.Net?

2
A. Each property consists of accessor as getting and set.
B. A property cannot be either read or write-only.
C. Properties can be used to store and retrieve values to and from the data
members of a class.
D. Properties are like actual methods that work like data members.

13. If a class ‘demo’ had ‘add’ property with getting and set accessors, then which
of the following statements will work correctly?

A. math.add = 20;
B. math m =  new math();
m.add = 10;
C. Console.WriteLine(math.add);
D. None of the mentioned

14. What will be the output of the following code snippet?


using System;

class sample

int i;

double k;

public sample (int ii, double kk)

i = ii;

k = kk;

double j = (i) + (k);

Console.WriteLine(j);

~sample()

3
double j = i - k;

Console.WriteLine(j);

class Program

static void Main(string[] args)

sample s = new sample(9, 2.5);

A. 0   0
B. 11.5   0
C. Compile-time error
D. 11.5 6.5

15. What will be the output of the following code snippet?


using System;

class program

static void Main(string[] args)

int x = 8;

int b = 16;

4
int c = 64;

x /= c /= b;

Console.WriteLine(x + " " + b+ " " +c);

Console.ReadLine();

A. 2  16   4
B. 4   8   16
C. 2   4    8
D. 8  16  64

16. Struct’s data members are ___ by default.

A. Protected
B. Public
C. Private
D. Default

17. The point at which an exception is thrown is called the _____.

A. Default point
B. Invoking point
C. Calling point
D. Throw point

18. Which of the following statements are correct for C# language?

A. Every derived class does not define its own version of the virtual method.
B. By default, the access mode for all methods in C# is virtual.
C. If a derived class, does not define its own version of the virtual method, then
the one present in the base class gets used.
D. All of the above.

19. What will be the output of the following code snippet?

5
using System;

class sample

public sample()

Console.WriteLine("constructor 1 called");

public sample(int x)

int p = 2;

int u;

u = p + x;

Console.WriteLine("constructor 2 called");

class Program

static void Main(string[] args)

sample s = new sample(4);

sample t = new sample();

Console.ReadLine();

6
}

A. constructor 1 called
constructor 2 called
B. constructor 2 called
constructor 1 called
C. constructor 2 called
constructor 2 called
D. error

20. Which of the following keywords is used to refer base class constructor to
subclass constructor?

A. this
B. static
C. base
D. extend

--------------------------------------------------------------------------------------------

21] static void Main(string[] args)

int a = 10, b = 20;

Console.WriteLine("{0},{0}", a, b);

1. 10,10
2. 10,20
3. 20,20
4. 20,10

22] static void Main(string[] args)

7
{

int a = 10, b = 20;

Console.WriteLine("{0}+{1}", a, b);

1. 30
2. 20+20
3. 10+10
4. 10+20

23] static void Main(string[] args)

Console.WriteLine(Console.Write("Hello"));

1. Error
2. 6Hello
3. Hello6
4. Hello5

24] static void Main(string[] args)

int a = 10, b = 10;

Console.WriteLine(a == b);

1. 1

8
2. a==b
3. True
4. true

25] static void Main(string[] args)

string text = "";

text = Console.ReadLine();

Console.WriteLine(text);

1. Hello
2. Hello world!
3. Helloworld!
4. None

26. Write a program :


Int[] arr={-2,-1,1,3,4}

Consider above array ,

1. If the sum of two consecutive numbers is 0 then that number should be skipped

Eg -2 + -1 =-3

-1 + 1 =0 --> skipped

So new array {-3,3,4}

-3 + 3 = 0  skipped

New Array : {4} --> Expected output

9
27. Write a program to reverse a string.

Input -> Hello

Output -> olleH

28. Write a program to reverse a word in sentence.

Input -> Hello World

Output -> olleH dlrow

29. Write a program to sort an array (without using any inbuilt function)

Input - > [2, 55,11,7,78]

Output -> [2,7,11,55,78]

30. Write a program to find highest duplicated item and its count from an array.

Input -> [2, 3, 1, 4, 55, 4, 6, 5, 9, 4, 6]

Output -> 4 – 3 Times

10

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy