TechBeamersTechBeamers
  • Python
    • Python Basic
    • Python OOP
    • Python Quiz
    • Python Examples
    • Python Interview
    • Python Selenium
    • Python Advanced
  • Java
    • Java Quiz
    • Java Interview
  • C
  • C#
  • SQL
  • MySQL
  • Selenium
    • Selenium Tutorial
    • TestNG Tutorials
    • Selenium Interview
    • Selenium Quiz
  • Testing
    • Software Testing
    • Manual Testing
    • Software Testing Quiz
    • Testing Interview Questions
  • Agile
  • More
    • Bookmarks
    • Customize
    • About Us
    • Contact
Search
More Tutorials
  • Agile Tutorial
  • Android Tutorial
  • Angular Tutorial
  • Linux Tutorial
  • TestNG Tutorial
Interview Q&A
  • Python Questions
  • Java Questions
  • PHP Questions
  • Web Dev Questions
  • Linux Questions
Coding Quizzes
  • Python Quiz
  • Java Quiz
  • Selenium Quiz
  • HTML CSS Quiz
  • Shell Script Quiz
ยฉ 2023 TechBeamers. All Rights Reserved.
Reading: Test C# Programming Skills โ€“ 15 Questions on Classes for Beginners
Share
Notification Show More
Aa
TechBeamersTechBeamers
Aa
  • Agile
  • Android
  • Angular
  • Best IDEs
  • C
  • C#
  • CPP
  • HTML
  • IOT
  • Java
  • Java Interview
  • Java Quiz
  • Linux
  • MySQL
  • PHP Interview
  • Python
  • Python Basic
  • Python Quiz
  • Python Examples
  • Python Advanced
  • Python Interview
  • Python OOP
  • Python Selenium
  • QA Interview
  • Selenium
  • Selenium Quiz
  • Selenium Interview
  • Shell Script Quiz
  • Software Testing
  • Software Testing Quiz
  • SQL Interview
  • Web Development
Search
  • Programming Tutorials
    • Python Tutorial
    • Python Examples
    • Java Tutorial
    • C Tutorial
    • MySQL Tutorial
    • Selenium Tutorial
    • Testing Tutorial
  • Top Interview Q&A
    • SQL Interview
    • Java Interview
    • C# Interview
    • PHP Interview
    • Python Interview
    • QA Interview
    • Selenium Interview
    • Web Dev Interview
  • Best Coding Quiz
    • Python Quiz
    • Java Quiz
    • Selenium Quiz
    • Testing Quiz
    • HTML CSS Quiz
    • ShellScript Quiz
    • C/C++ Quiz
  • Bookmarks
    • My Bookmarks
    • My Interests
Follow US
ยฉ 2023 TechBeamers. All Rights Reserved.
TechBeamers > Blog > C# Interview > Test C# Programming Skills โ€“ 15 Questions on Classes for Beginners
C# Interview

Test C# Programming Skills โ€“ 15 Questions on Classes for Beginners

Last updated: 2023/05/22 at 12:56 PM
By Meenakshi Agarwal
Share
13 Min Read
SHARE

C# is undoubtedly one of the most interesting programming languages. And weโ€™ve already covered some of its features in our earlier posts. Today, we are presenting a C# programming test with 15 questions and answers on classes.

Contents
Test C# Programming SkillsObjectVarDynamicC# programming test with 15 questions and answers on classesQ-1. Which of the following can be used to define the member of a class externally?Q-2. Which of the following operator can be used to access the member function of a class?Q-3. What will be the output of the following code snippet?Q-4. Which of the following statements are correct for the given code snippet:Q-5. Which of the following gives the correct count of the constructors that a class can define?Q-6. What will be the output of the following code snippet?Q-7. What will be the output of the following code snippet?Q-8. What will be the output of the following code snippet?Q-9. Which of the following statements correctly tell the differences between โ€˜=โ€™ and โ€˜==โ€™ in C#?Q-10. What will be the output of the following code snippet?Q-11. What will be the output of the following code snippet?Q-12. What is the correct name of a method which has the same name as that of class and used to destroy objects?Q-13. What will be the output of the following code snippet?Q-14. What will be the output of the following code snippet?Q-15. What will be the output of the following code snippet?Summary โ€“ C# programming test with 15 questions on classes

There are a few compelling facts that you should know about C#. First of all, the obvious one, itโ€™s an object-oriented language and is strongly typed.

With this strict type checking feature, the bulkย ofย programming errorsย includingย runtime as well as compile time gets uncovered at a very early stage.

It saves programmers from getting into any unforeseen issue later in the project life-cycle.

Test C# Programming Skills

Before you get into aย war with theย C# programming test, buy a little time to know about the three most important data types in C#. These are none other than the trio โ€“ Object, Var, and Dynamic types. Letโ€™s check out what draws a distinction among them?

Object

It took birth with C# 1.0. It creates a generic entity that can hold any type. A method can accept it as an argument and also return the object type. Without casting to an actual type, you wonโ€™t be able to use it. Itโ€™s primarily useful when the data type of target entity is not known.

Var

Itโ€™s relatively new and gets introduced with C# 3.0. Though, it too can store any value but requires initialization during declaration. It is type safe and doesnโ€™t make the compiler to flag an error at runtime. Neither it supports to pass as a function argument nor can a function return it. The compiler relaxes it to work without being cast. You can utilize it to handle any of the anonymous types.

Dynamic

Itโ€™s the newest of the C# construct which got its shape with C# 4.0. It stores values in the same manner as the legacy Var does. Itโ€™s not type safe. And the compiler wonโ€™t know anything about the type. There is no need to cast. But you must aware of the properties and methods the stored type supports. Otherwise, you may get into runtime issues. It is fit for situations where there are requirements to use concepts like Reflection or Dynamic languages or COM methods.

So now, you know the essentials of three object-oriented data types of C#. Please go ahead to the interview questions/answers section.

C# programming test with 15 questions and answers on classes

C# Programming Test with 15 Questions and Answers
C# Programming Test

Q-1. Which of the following can be used to define the member of a class externally?

a) :
b) ::
c) #
d) none of the mentioned

[toggle title=โ€View answer.โ€]Answer. b)[/toggle]

ย 

Q-2. Which of the following operator can be used to access the member function of a class?

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

[toggle title=โ€View answer.โ€]Answer. c)[/toggle]

ย 

Q-3. What will be the output of the following code snippet?

using System;
class emp
  {
      public string name;
      public string address;
      public void display()
      {
          Console.WriteLine("{0} is in city {1}", name, address);
      }
  }
  class Program
  {
      static void Main(string[] args)
      {
          emp obj = new emp();
          obj.name = "Akshay";
          obj.address = "new delhi";
          obj.display();
          Console.ReadLine();
      }
  }

a) Syntax error
b) {0} is in city {1} Akshay new delhi
c) Akshay is in new delhi
d) Akshay is in city new delhi

e) executes successfully and prints nothing

[toggle title=โ€View answer.โ€]Answer. d)[/toggle]

ย 

Q-4. Which of the following statements are correct for the given code snippet:

shape obj;
obj = new shape();

a) creates an object of class shape.
b) To create an object of type shape on the heap or stack depending on its size.
c) create a reference obj of the class shape and an object of type shape on the heap.
d) create an object of type shape on the stack.

[toggle title=โ€View answer.โ€]Answer. c)[/toggle]

ย 

Programmers Should Also Follow the Below Post.

[alert-note]โ˜› Check out 15 C# Questions โ€“ For, While Loops and If Else Statements.[/alert-note]

ย 

Q-5. Which of the following gives the correct count of the constructors that a class can define?

a) 1
b) 2
c) Any number
d) None of the above

[toggle title=โ€View answer.โ€]Answer. c)[/toggle]

ย 

Q-6. What will be the output of the following code snippet?

using System;
class sample
{
     public static void first()
     {
         Console.WriteLine("first method");
     }
     public void second()
     {
         first();
         Console.WriteLine("second method");
     }
     public void second(int i)
     {
         Console.WriteLine(i);
         second();
     }
}
class program
{
     public static void Main()
     {
         sample obj = new sample();
         sample.first();
         obj.second(10);
     }
}

a) second method
ย ย ย  10
ย ย ย  second method
ย ย ย  first method
b) first method
ย ย ย  10
ย ย ย  first method
ย ย ย  second method
c) first method
ย ย ย  10
d) second method
ย ย ย  10
ย ย ย  first method.

[toggle title=โ€View answer.โ€]Answer. b)[/toggle]

ย 

Q-7. What will be the output of the following code snippet?

using System;
class program
{
    static void Main(string[] args)
    {
        int num = 2;
        fun1 (ref num);
        Console.WriteLine(num);
        Console.ReadLine();
    }
    static void fun1(ref int num)
    {
        num = num * num * num;
    }
}

a) 8
b) 0
c) 2
d) 16

[toggle title=โ€View answer.โ€]Answer. a)[/toggle]

ย 

Q-8. What will be the output of the following code snippet?

using System;
class program
{
    static void Main(string[] args)
    { 
        int[] arr = new int[] {1 ,2 ,3 ,4 ,5 };
        fun1(ref arr);
        Console.ReadLine();
    }
    static void fun1(ref int[] array)
    {
        for (int i = 0; i < array.Length; i=i+2)
        {
            array[i] = array[i] + 10;
        }
        Console.WriteLine(string.Join(",", array));
    }
}

a) 1 2 3 4 5
b) 11 12 13 14 15
c) 11 2 13 4 15
d) 1ย  3 5 7 9

[toggle title=โ€View answer.โ€]Answer. c)[/toggle]

ย 

Q-9. Which of the following statements correctly tell the differences between โ€˜=โ€™ and โ€˜==โ€™ in C#?

a) โ€˜==โ€™ operator is used to assign values from one variable to another variable
โ€˜=โ€™ operator is used to compare value between two variables
b) โ€˜=โ€™ operator is used to assign values from one variable to another variable
โ€˜==โ€™ operator is used to compare value between two variables
c) No difference between both operators
d) None of the mentioned

[toggle title=โ€View answer.โ€]Answer. b)[/toggle]

ย 

Q-10. What will be the output of the following code snippet?

using System;
class program
{
   static void Main(string[] args)
    {
        int x = 4 ,b = 2;
        x -= b/= x * b;
        Console.WriteLine(x + " " + b);
        Console.ReadLine();
    } 
}

a) 4 2
b) 0 4
c) 4 0
d) None of the mentioned

[toggle title=โ€View answer.โ€]Answer. c)[/toggle]

ย 

Q-11. 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;
       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

[toggle title=โ€View answer.โ€]Answer. a)[/toggle]

ย 

Q-12. What is the correct name of a method which has the same name as that of class and used to destroy objects?

Note โ€“ This method gets called automatically when the application is at the final stage waiting for the process to terminate.

a) Constructor
b) Finalize()
c) Destructor
d) End

[toggle title=โ€View answer.โ€]Answer. c)[/toggle]

ย 

Q-13. 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()
      {
          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

[toggle title=โ€View answer.โ€]Answer. d)[/toggle]

ย 

Donโ€™t Miss to Check out this Awesome Post.

[alert-note]โ˜› ย 15 C# Interview Questions that Every Beginner Should Read Once.[/alert-note]

ย 

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

using System;
class sum
  {
      public int value;
      int num1;
      int num2;
      int num3;
      public sum ( int a, int b, int c)
      {
          this.num1 = a;
          this.num2 = b;
          this.num3 = c;
      }
      ~ sum()
      {
          value = this.num1 * this.num2 * this.num3;
          Console.WriteLine(value);
      }
  }    
  class Program
  {
      public  static void Main(string[] args)
      {
          sum s = new sum(4, 5, 9);
      }
  }

a) 0
b) 180
c) Compile time error
d) 18

[toggle title=โ€View answer.โ€]Answer. b)[/toggle]

ย 

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

using System;
class Program
{
    static void Main(string[] args)
    {
        int num = 5;
        int square = 0, cube = 0;
        Mul (num, ref square, ref cube);
        Console.WriteLine(square + " & " +cube);
        Console.ReadLine();
    }
    static void Mul (int num, ref int square, ref int cube)
    {
        square = num * num;
        cube = num * num * num;
    }
}

a) 125 & 25
b) 25 & 125
c) Compile time error
d) 10 & 15

[toggle title=โ€View answer.โ€]Answer. b)[/toggle]

Summary โ€“ C# programming test with 15 questions on classes

We wish youโ€™d enjoyed running through the C# programming test. And it might get you a quick brush up of your object-oriented skills.

It would be a pleasure for us to have your feedback on the questions.

Your valuable response, a question or comments about this post are always welcome. Also, if you liked the above post, then donโ€™t mind following us onย our social media (facebook/twitter) accounts.

Check out more CSharp Q&A on various programming topics:

1. 50 CSharp Coding Interview Questions
2. 15 CSharp Programming Interview Questions
3. 15 CSharp Interview Questions Every Programmer
4. 15 CSharp Questions on For, While and If Else
5. 15 CSharp Programming Questions on Classes
6. 20 CSharp OOPS Interview Questions Set-1
7. 20 CSharp OOPS Interview Questions Set-2
8. 25 CSharp OOPs Interview Questions Set-3
9. 35 CSharp Exception Handling Questions

Best,

TechBeamers

You Might Also Like

C# Exception Handling โ€“ 35 Questions Programmers Should not Miss

25 C# OOPs Interview Questions Every Programmer Should Read

C# Object-Oriented Interview Questions Set-2

50 Must Know C# Coding Interview Questions for Developers

20 C# Programming Questions on Object Oriented Concepts

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
Loading
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Twitter LinkedIn Email Copy Link
Share
By Meenakshi Agarwal
Follow:
Meenakshi Agarwal is a founder of TechBeamers and has extensive experience in Software Programming and Testing. Here, she aims to share her expertise by providing excellent tutorials for beginners to learn Python, Java, Selenium, C, C++, CSharp, Angular, PHP, JavaScript, Agile, Manual and Automation Testing concepts.
Previous Article Seven Steps A Successful Test Automation Developer Should Follow Seven Steps to Become a Successful Test Automation Developer
Next Article C# OOPS Interview Questions 20 C# Programming Questions on Object Oriented Concepts
2 Comments 2 Comments
  • Meenakshi Agarwal says:
    August 11, 2017 at 10:53 pm

    Hi โ€“ This question and its options are fixed now. Thanks for reporting to us.

  • XY says:
    August 11, 2017 at 4:54 pm

    Q-3.
    e) Akshay is in city

Leave a Reply

Your email address will not be published. Required fields are marked *

Latest Tutorials

Learn how to do factorial in python
Factorial Program in Python with Examples
Python Examples June 9, 2023
4 ways to find all possible string permutation in Python
Find All Possible Permutation of a String in Python
Python Examples April 30, 2023
SQL Exercises with Sample Table and Demo Data
SQL Exercises โ€“ Complex Queries
SQL Interview May 10, 2020
//

From Python to Java and everything in between, weโ€™ve got you covered with practical and actionable advice designed to help you level up your coding skills.

Quick Link

  • MY BOOKMARKS
  • MY INTERESTSNew
  • CONTACT US
  • BLOG INDEX

Top Categories

  • AGILE
  • BEST IDEsHot
  • PYTHON
  • SQL

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

Loading
TechBeamersTechBeamers
Follow US
ยฉ 2023 TechBeamers. All Rights Reserved.
  • Contact Page
  • About Us
  • Terms of Use
  • Privacy Policy
  • Disclaimer
Join Us!

Subscribe to our newsletter and never miss our latest news, podcasts etc..

Loading
Zero spam, Unsubscribe at any time.