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

C# is undoubtedly one of the most interesting programming languages. And we’ve already covered a bit of its features in earlier posts. Today, we are presenting a C# programming test with 15 questions and answers 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 any 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 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

View answer.
Answer. b)

 

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

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

View answer.
Answer. c)

 

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

a) Syntax error
b) {0} is in city{1} Akshay new delhi
c) Akshay is in new delhi
d) executes successfully and prints nothing

View answer.
Answer. c)

 

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

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.

View answer.
Answer. c)

 

Programmers Should Also Follow the Below Post.

 

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

View answer.
Answer. c)

 

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

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.

View answer.
Answer. b)

 

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

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

View answer.
Answer. a)

 

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

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

View answer.
Answer. c)

 

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

View answer.
Answer. b)

 

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

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

View answer.
Answer. c)

 

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

a) 2 16 4
b) 4 8 16
c) 2 4 8
d) 8 16 64

View answer.
Answer. a)

 

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 final stage waiting for the process to terminate.

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

View answer.
Answer. c)

 

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

a) 0 0
b) 11.5 0
c) Compile time error
d) 11.5 6.5

View answer.
Answer. d)

 

Don’t Miss to Check out this Awesome Post.

 

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

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

View answer.
Answer. b)

 

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

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

View answer.
Answer. b)

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.

Best,

TechBeamers.

Leave a Reply


*