Class & Objects

The ____ language allows more than one method in a single class

  • A) c#
  • B) j#
  • C) c++
  • D) c
  • E) pascal

2. Which of the following statements is correct?  

  • A) C#.NET is a structured programming language.
  • B) Object Oriented Programming paradigm stresses on dividing the logic into smaller parts and writing procedures for each part.
  • C) Procedural Programming paradigm is different than structured programming paradigm.
  • D) Classes and objects are corner stones of structured programming paradigm.
  • E) Object Oriented Programming paradigm gives equal importance to data and the procedures that work on the data.

3. The this reference gets created when a member function (non-shared) of a class is called.  

  • A) True
  • B) False

Which of the following statements are correct about the C#.NET code snippet given below?

 DesignGoDynamic c;
c = new  DesignGoDynamic ();

1.    It will create an object called DesignGoDynamic .
2.    It will create a nameless object of the type DesignGoDynamic .
3.    It will create an object of the type DesignGoDynamic on the stack.
4.    It will create a reference c on the stack and an object of the type DesignGoDynamic on the heap.
5.    It will create an object of the type DesignGoDynamic either on the heap or on the stack depending on the size of the object. 

  • A) 1,3
  • B) 2,4
  • C) 3,5
  • D) 4,5
  • E) None of these

5. Which of the following statements are correct about the this reference? 1. this reference can be modified in the instance member function of a class. 2. Static functions of a class never receive the this reference. 3. Instance member functions of a class always receive a this reference. 4. this reference continues to exist even after control returns from an instance member function. 5. While calling an instance member function we are not required to pass the this reference explicitly.  

  • A) 1, 4
  • B) 3,4
  • C) 2,5
  • D) 2,3,5
  • E) All of these

6. Which of the following statements is correct about classes and objects in C#.NET?  

  • A) Class is a value type.
  • B) Since objects are typically big in size, they are created on the stack.
  • C) Objects of smaller size are created on the heap.
  • D) Smaller objects that get created on the stack can be given names.
  • E) Objects are always nameless.

7. Can you prevent a class from overriding?  

If you define a class as “Sealed” in C # you cannot inherit the class any further.

8. What is the difference between Class and structure’s?  

Following are the key differences between them:-
• Structures are value types and classes are reference types. So structures use stack and classes use heap.
• Structures members cannot be declared as protected, but class members can be. You cannot do inheritance in structures.
• Structures do not require constructors while classes require.
• Objects created from classes are terminated using Garbage collector. Structures are not destroyed using GC.

9. What are similarities between Class and structure?  

Following are the similarities between classes and structures:-
• Both can have constructors, methods, properties, fields, constants, enumerations, events, and event handlers.
• Structures and classes can implement interface.
• Both of them can have constructors with and without parameter.
• Both can have delegates and events.

10. What are features of Static classes ?  

Following are features of Static/Shared classes:-
• They cannot be instantiated. By default, a object is created on the first method call to that object.
• Static/Shared classes cannot be inherited.
• Static/Shared classes can have only static members.
• Static/Shared classes can have only static constructor.

11. Explain Structure.  

12. Explain Constructors of C# structure.  

In c#, a structure can have constructors. A constructor is a special member of the structure. It can be used to initialize variables of the structure when its object is created. The name of constructor must be the same as the name of structure. The constructor called automatically when the keyword "new" is used to create the objects of the structure.
struct student
    public string stnumber;
    public string stname;
    public string stsex;
    public student(string id,string name,string sex){ //constructor

student st=new student("s001","Dara Yuk","M"); //create object

Note: a structure in C# can have other members such as methods, properties, and events. However, if you have these kinds of things in your program, you should consider using class instead.

Java Interview Question

.Net Interview Question

PHP Interview Question

AngularJS Interview Questions