TechBeamersTechBeamers
  • Learn ProgrammingLearn Programming
    • Python Programming
      • Python Basic
      • Python OOP
      • Python Pandas
      • Python PIP
      • Python Advanced
      • Python Selenium
    • Python Examples
    • Selenium Tutorials
      • Selenium with Java
      • Selenium with Python
    • Software Testing Tutorials
    • Java Programming
      • Java Basic
      • Java Flow Control
      • Java OOP
    • C Programming
    • Linux Commands
    • MySQL Commands
    • Agile in Software
    • AngularJS Guides
    • Android Tutorials
  • Interview PrepInterview Prep
    • SQL Interview Questions
    • Testing Interview Q&A
    • Python Interview Q&A
    • Selenium Interview Q&A
    • C Sharp Interview Q&A
    • PHP Interview Questions
    • Java Interview Questions
    • Web Development Q&A
  • Self AssessmentSelf Assessment
    • Python Test
    • Java Online Test
    • Selenium Quiz
    • Testing Quiz
    • HTML CSS Quiz
    • Shell Script Test
    • C/C++ Coding Test
Search
  • Python Multiline String
  • Python Multiline Comment
  • Python Iterate String
  • Python Dictionary
  • Python Lists
  • Python List Contains
  • Page Object Model
  • TestNG Annotations
  • Python Function Quiz
  • Python String Quiz
  • Python OOP Test
  • Java Spring Test
  • Java Collection Quiz
  • JavaScript Skill Test
  • Selenium Skill Test
  • Selenium Python Quiz
  • Shell Scripting Test
  • Latest Python Q&A
  • CSharp Coding Q&A
  • SQL Query Question
  • Top Selenium Q&A
  • Top QA Questions
  • Latest Testing Q&A
  • REST API Questions
  • Linux Interview Q&A
  • Shell Script Questions
© 2024 TechBeamers. All Rights Reserved.
Reading: Test C# Programming Skills – 15 Questions on Classes for Beginners
Font ResizerAa
TechBeamersTechBeamers
Font ResizerAa
  • Python
  • SQL
  • C
  • Java
  • Testing
  • Selenium
  • Agile Concepts Simplified
  • Linux
  • MySQL
  • Python Quizzes
  • Java Quiz
  • Testing Quiz
  • Shell Script Quiz
  • WebDev Interview
  • Python Basic
  • Python Examples
  • Python Advanced
  • Python OOP
  • Python Selenium
  • General Tech
Search
  • Programming Tutorials
    • Python Tutorial
    • Python Examples
    • Java Tutorial
    • C Tutorial
    • MySQL Tutorial
    • Selenium Tutorial
    • Testing Tutorial
  • Top Interview Q&A
    • SQL Interview
    • Web Dev Interview
  • Best Coding Quiz
    • Python Quizzes
    • Java Quiz
    • Testing Quiz
    • ShellScript Quiz
Follow US
© 2024 TechBeamers. All Rights Reserved.
CSharp InterviewWeb Development

Test C# Programming Skills – 15 Questions on Classes for Beginners

Last updated: Feb 24, 2024 9:22 pm
By Meenakshi Agarwal
Share
13 Min Read
C# Programming Test with 15 Questions and Answers
C# Programming Test.
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 in classes.

Contents
ObjectVarDynamicC# programming test with 15 questions on classesQ-1. Which of the following can be used to define the member of a class externally?Q-2. Which of the following operators 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 is 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 tells 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 that has the same name as that of class and is 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?

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 learn 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 the target entity is not known.

Var

It’s relatively new and was 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 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 be 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, 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 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

Hover here to view the answer!
Answer. b)

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

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

Hover here to view the answer!
Answer. c)

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 the city of New Delhi
e) Executes successfully and prints nothing

Hover here to view the answer!
Answer. d)

Q-4. Which of the following statements is 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 object of the class shape and an object of type shape on the heap.
d) Create an object of type shape on the stack.

Hover here to view the answer!
Answer. c)

Programmers Should Also Follow the Below Post.

Checkout: 15 C# Questions – For, While Loops, and If Else Statements

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

Hover here to view the answer!
Answer. c)

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.

Hover here to view the answer!
Answer. b)

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

Hover here to view the answer!
Answer. a)

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

Hover here to view the answer!
Answer. c)

Q-9. Which of the following statements correctly tells 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

Hover here to view the answer!
Answer. b)

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

Hover here to view the answer!
Answer. c)

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

Hover here to view the answer!
Answer. a)

Q-12. What is the correct name of a method that has the same name as that of class and is 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

Hover here to view the answer!
Answer. c)

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

Hover here to view the answer!
Answer. d)

Don’t Miss to Check out this Awesome Post.

Checkout: 15 C# Interview Questions that Every Beginner Should Read Once

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

Hover here to view the answer!
Answer. b)

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

Hover here to view the answer!
Answer. b)

Summary – C# programming test with 15 questions on classes

We hope you enjoyed running through the C# programming test. And it might get you a quick brush up on 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 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

Learn Web Development with Engaging Quizzes!

20 Common .NET Coding Interview Questions with Answers

Generate Random Characters With JavaScript Math & Crypto Modules

Discover the Most Asked HTML Interview Questions

JavaScript Interview Questions for 2024

TAGGED:CSharp Interview Questions
Meenakshi Agarwal Avatar
By Meenakshi Agarwal
Follow:
Hi, I'm Meenakshi Agarwal. I have a Bachelor's degree in Computer Science and a Master's degree in Computer Applications. After spending over a decade in large MNCs, I gained extensive experience in programming, coding, software development, testing, and automation. Now, I share my knowledge through tutorials, quizzes, and interview questions on Python, Java, Selenium, SQL, and C# on my blog, TechBeamers.com.
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

Popular Tutorials

SQL Interview Questions List
50 SQL Practice Questions for Good Results in Interview
SQL Interview Nov 01, 2016
Demo Websites You Need to Practice Selenium
7 Sites to Practice Selenium for Free in 2024
Selenium Tutorial Feb 08, 2016
SQL Exercises with Sample Table and Demo Data
SQL Exercises – Complex Queries
SQL Interview May 10, 2020
Java Coding Questions for Software Testers
15 Java Coding Questions for Testers
Selenium Tutorial Jun 17, 2016
30 Quick Python Programming Questions On List, Tuple & Dictionary
30 Python Programming Questions On List, Tuple, and Dictionary
Python Basic Python Tutorials Oct 07, 2016
//
Our tutorials are written by real people who’ve put in the time to research and test thoroughly. Whether you’re a beginner or a pro, our tutorials will guide you through everything you need to learn a programming language.

Top Coding Tips

  • PYTHON TIPS
  • PANDAS TIPSNew
  • DATA ANALYSIS TIPS
  • SELENIUM TIPS
  • C CODING TIPS
  • GDB DEBUG TIPS
  • SQL TIPS & TRICKS

Top Tutorials

  • PYTHON TUTORIAL FOR BEGINNERS
  • SELENIUM WEBDRIVER TUTORIAL
  • SELENIUM PYTHON TUTORIAL
  • SELENIUM DEMO WEBSITESHot
  • TESTNG TUTORIALS FOR BEGINNERS
  • PYTHON MULTITHREADING TUTORIAL
  • JAVA MULTITHREADING TUTORIAL

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

Loading
TechBeamersTechBeamers
Follow US
© 2024 TechBeamers. All Rights Reserved.
  • About
  • Contact
  • Disclaimer
  • Privacy Policy
  • Terms of Use
TechBeamers Newsletter - Subscribe for Latest Updates
Join Us!

Subscribe to our newsletter and never miss the latest tech tutorials, quizzes, and tips.

Loading
Zero spam, Unsubscribe at any time.
x