Become a GOLD member of Deccansoft and get access to 40+ courses!!
NewBatches/Webinars
Packages
Gold Membership
Bestseller
Microsoft Azure Suite & Suite Plus
Power Platform Acadamy
New
Azure DevOps Expert & Expert Plus
MS.NET Foundation For Beginners
MS.NET Full Stack Developer
UI / Web Development
SQL Server & MSBI Tools
Software Testing
Courses
MS.NET Courses (Includes Live Project)
Complete C#, OOPs and Windows Programing
ASP.NET MVC Online Training
ASP.NET WebForms
ASP.NET Core
WCF incl. Web Services and Remoting
WPF incl. MVVM and Prism
LINQ and Entity Framework
Live Project Training for Developing Enterprise Application
Live Project using Ntier Arch (.NET5 + EF Core + Angular)
Microservices using .NET Core
Gold Membership
CareerStep IT Program
Client-side UI Technologies
Building Static Web Pages using HTML and CSS
JavaScript and HTML DOM
jQuery, AJAX and JSON
Building Interactive Web Pages using HTML5 and CSS3
BootStrap + Live Examples
AngularJS + Live Project
Angular + Typescript
ReactJS
KnockoutJS
Xamarin
SQL Server + MSBI
SQL Server 2017
Querying Data with Transact-SQL(70-761)
SQL Server Integration Service (SSIS)
SQL Server Reporting Service (SSRS)
SQL Service Analysis Service (SSAS)
Cloud Computing / Azure / AWS
AZ-900: Microsoft Azure Fundamentals
Azure Suite (AZ-104+AZ-204+AZ-305+ AZ-500)
AZ-104: Microsoft Azure Administrator
AZ-204: Developing Solutions for Microsoft Azure
AZ-305: Microsoft Azure Architect Technologies and Design
DP-203: Data Engineering on Microsoft Azure
Amazon Web Services (AWS)
DevOps Expert
AZ-400: Microsoft Azure DevOps
Docker by Sandeep Soni
Kubernetes by Sandeep Soni
Docker & Kubernetes by Rahul Rampurkar
IaC Using Terraform
Powershell
Microsoft Power Platform
Microsoft Power Platform
Data Analytics using PowerBI (DA-100)
Testing Tools
Manual Testing
Selenium Testing with Java(Live Training)
Others
Python Programming
C and Data Structure
Core Java
OOPs and C++
Advance Java
Complete Azure Training
Pricing
Videos
Testimonials
Azure Certification
Contact Us
Login
Login or Register
×
Sign In
Register
Forgot Password?
How did you find us
WhatsApp
YouTube
LinkedIn
Facebook
Telegram
Twitter
Google
Referred by Friend
Refresh
Input symbols
By clicking Register, you accept to the
terms and conditions
and that you have read our
privacy policy.
Recover Password
×
Submit
Enquiry Now
Where did you come to know about us
WhatsApp
YouTube
LinkedIn
Facebook
LinkedIn Ad
Email
Twitter
Google
Referred
Other
Refresh
Input symbols
OOPs - Programming Encapsulation
Interview Questions and Answer
1. class CA { public static void Foo() { } } class Program { public static void Main() { CA a; a.Foo(); } } The above program gives
Options:
a. Compilation Error
b. Runtime exception is thrown
c. No error
d. All of the above
Reveal Answer
2. class CA { //....... } class Program { public static void Main() { CA a; // .... } } what is the default value of 'a'?
Options:
a. null
b. nothing
c. Explicitly assign in C#
d. None of the above
Reveal Answer
3. When an object of a class is created, memory is allocated for its member variables on the heap but they are not automatically initialized. Is this statement true or false?
Options:
a. True
b. False
Reveal Answer
4. public decimal Balance { get { return _Balance; } }
Options:
a. Balance is readonly property
b. Balance is writeonly property
c. Balance is global variable
d. Balance is readonly and writeonly property
Reveal Answer
5. class CA { private int _Id; public int Id { get { return _Id; } set { _Id = value; } } } What is the datatype of "value" in set block?
Options:
a. string
b. double
c. int
d. none of the above
Reveal Answer
6. Using a property in VB.NET the field member can be restricted with...
Options:
a. ReadOnly access
b. WriteOnly access
c. Either ReadOnly or WriteOnly access
d. None
Reveal Answer
7. What is the default access specifier for a member of a class?
Options:
a. public
b. private
c. protected
d. None
Reveal Answer
8. class CA { private CA() { } } class Program { static void Main(string[] args) { CA a = new CA(); } } What happens if the above program is compiled ?
Options:
a. No result
b. Compiles successfully.
c. Compilation Error.
d. None of the above.
Reveal Answer
9. class Program { static void Main(string[] args) { CA a; a = new CA(10); Console.WriteLine(a.Id); } } public class CA { private int _Id; public int Id { get { return _Id; } set { _Id = value; } } public CA(int Id) { Id = Id; } } What is the Output of this program?
Options:
a. 0
b. 10
c. compilation Error
d. Exception
Reveal Answer
10. When is the object ready for garbage collection?
Options:
a. The value of the object is changed.
b. Objects does not have reference
c. When using type casting
d. None of the above
Reveal Answer
11. class Program { public static void Main() { CA a = new CA(); CA b = a; a = null; } } class CA { //.. } In the above code among 'a' and 'b' which variable is ready for garbage collection?
Options:
a. a
b. b
c. None
Reveal Answer
12. class CA { bool Foo() { CA x = null; if (x.Equals(null)) return true; else return false; } static void Main() { CA a = new CA(); bool result = a.Foo(); Console.WriteLine(result); } } What is the result of above program.
Options:
a. Returns True
b. Returns False
c. Compilation Error
d. Runtime Exception
Reveal Answer
13. public class CA { private string _Name; public string Name { get { return _Name; } set { if (value.Length > 8) throw new ApplicationException("Name cannot be > 8 characters"); _Name = value; } } } class Program { public static void Main() { CA objCA = new CA(); objCA.Name = "Encyclopedia"; } } What would be the output of the above program?
Options:
a. Compiletime Error.
b. Exception is raised
c. Will be executed successfully.
Reveal Answer
14. Is it possible to force the activation of Garbage collection?
Options:
a. Yes
b. No
Reveal Answer
15. Can we overload constructors
Options:
a. Yes
b. No
Reveal Answer
16. class CA { public CA(int a) { } } Can we create an object of a class as below CA a = new CA();
Options:
a. Yes
b. No
Reveal Answer
17. Copy constructor is used to ______
Options:
a. copy few parameters
b. create an object by name “copy”
c. create an object by passing an initialized object of the same type
d. There is no copy constructor available
Reveal Answer
18. Can a constructor be invoked explicitly Modified: Is it possible to invoke constructor explicitly?
Options:
a. Yes
b. No
Reveal Answer
19. class CA { public CA() { Console.WriteLine("In Default"); } public CA(int a) : this() { Console.WriteLine("In Parameterised"); } } class Program { static void Main(string[] args) { CA a = new CA(10); } } What is the output?
Options:
a. Compilation error
b. In default
c. In parameterized
d. Both B and C
Reveal Answer
20. If a class doesn’t have any type of constructor in definition, a public _____________ is automatically added to it by the language compiler.
Options:
a. Default parameterized constructor
b. Default constructor
c. Static constructor
Reveal Answer
21. class CA { public New() { Console.WriteLine("Hello World"); } } class Program { static void Main(string[] args) { CA a = new CA(); } } What is the output?
Options:
a. Hello World
b. Compilation Error
c. Runtime Error
d. None
Reveal Answer
22. Can we declare the constructor of a class as Private?
Options:
a. Yes
b. No
Reveal Answer
23. We can overload destructors
Options:
a. Yes
b. No
Reveal Answer
24. Can we declare destructor as public?
Options:
a. Yes
b. No
Reveal Answer
25. class CA { ~CA() { Console.WriteLine("In Destructor"); } } class Program { static void Main(string[] args) { CA a = new CA(); a = null; Console.WriteLine("Main ends"); } } What is the output?
Options:
a. Main ends
b. In destructor
c. Both A and B
d. Compilation error
Reveal Answer
26. When is destructor invoked?
Options:
a. When an object is no longer used by the application
b. When program exits
c. When invoked by GC
d. All of the above
Reveal Answer
27. Class CA { public void CA() { Console.WriteLine("In Constructor"); } //.... } class Program { static void Main(string[] args) { CA a = new CA(); } } What is the output?
Options:
a. In destructor
b. Null
c. Compilation error
Reveal Answer
28. class CA { public CA() { Console.WriteLine("In default constructor"); } //.... } class Program { static void Main(string[] args) { Console.WriteLine("Main Begins"); CA a; Console.WriteLine("Main Ends"); } }
Options:
a. Main Begins
b. Main Ends
c. In default constructor
d. Both A and B
e. A, C and then B
Reveal Answer
29. struct SA { int M1, M2; public SA() { } } What happens if this code is compiled?
Options:
a. Compilation error
b. No compilation error but runtime error when this structure is used
c. No compilation error and no runtime error
d. Runtime exception is thrown if this structure is instantiated
Reveal Answer
30. struct SA { int M1, M2; public SA(int m1) { M1 = m1; } } Is anything wrong in the above structure?
Options:
a. Yes
b. No
Reveal Answer
31. When are static members of the class allocated memory.
Options:
a. When the object is created
b. When the class is loaded
c. When the application is started
d. None of the above
Reveal Answer
32. When is the class loaded by class loader in CLR?
Options:
a. When the first instance of the class is created
b. When the static member of the class is accessed for the first time
c. Both A and B
Reveal Answer
33. Static members of the class can be used for storing global data in the application
Options:
a. Yes
b. No
Reveal Answer
34. class CA { static CA() { } } What is the name given to the mentioned member of class CA?
Options:
a. Constructor
b. Static constructor
c. Static method
d. None of the above
Reveal Answer
35. Which of the following is true about static constructor
Options:
a. To initialize static members of the class
b. To initialize static and instance members of the class
c. Static constructor can be overloaded
d. static constructor must be public
Reveal Answer
36. Arrange the following in sequence when the first object is created i. Instance constructor is executed. ii. Class is loaded. iii. Instance members are loaded and allocated memory. iv. Shared members are loaded and allocated memory. v. Shared constructor is executed.
Options:
a. ii, ii, v, iv ,iii
b. ii ,v ,iv ,ii ,i
c. ii ,iv ,v, i, iii
Reveal Answer
37. Static constructor can access instance members of the class.
Options:
a. Yes
b. No
Reveal Answer
38. class CA { public static int S1; private static int S2; public int I1 } If 5 objects of this class is created then how many copies of S1, S2 and I1 are allocated memory.
Options:
a. 1 1 1
b. 1 0 1
c. 1 0 5
d. 1 1 5
e. 1 5 5
f. 5 1 5
Reveal Answer
39. class SA { public static int S1; static SA() { S1++; Console.WriteLine("In Static contructor: " + S1); } public SA() { ++S1; Console.WriteLine("In constructor: " + S1); } } class Program { static void Main(string[] args) { SA a = new SA(); } } What is the output?
Options:
a. In Static constructor: 1
b. In constructor: 2
c. Both A and B
Reveal Answer
40. static class SA { public static int S1; static SA() { S1++; Console.WriteLine("In Static contructor: " + S1); } public SA() { S1++; Console.WriteLine("In constructor: " + S1); } } class Program { static void Main(string[] args) { SA a = new SA(); } } What is the o/p?
Options:
a. In Static constructor: 1
b. In constructor: 2
c. Both A and B
d. Compilation error
Reveal Answer
41. class SA { public static int S1 = 5; public int M1 = 5; public static void Foo() { S1++; M1++; } } class Program { static void Main() { SA a = new SA(); SA.Foo(); Console.WriteLine(a.M1 + " " + SA.S1); } } What is the o/p?
Options:
a. Compilation Error
b. Runtime Exception
c. 1 1
d. 6 6
e. 1 6
f. 6 1
Reveal Answer
42. Can we access static members of a class in instance method of same class? Justify your answer?
Options:
a. Yes
b. No
Reveal Answer
43. class SA { public static int _S1 = 0; public _______ int S1 { get { return _S1; } } } Fill in the blank above?
Options:
a. Static
b. Blank
c. Both A and B
Reveal Answer
44. Class SA { public static int S1 = 0; public int M1 = 10; public static void Foo() { SA a = new SA(); Console.WriteLine(a.M1); } } class Program { static void Main() { SA.Foo(); } } What is the o/p? Justify your answer?
Options:
a. 0
b. 10
c. Compilation Error
d. Runtime Exception
Reveal Answer
45. What is a Singleton Class?
Options:
a. Can be accessed globally
b. Instantiated only once
c. Singleton's constructor is set to private so that there be only one instance of this class.
d. All of the above
Reveal Answer
46. class SingletonDemo { public int Data; private static SingletonDemo obj; ________ SingletonDemo () { } public _______ ________ GetObject() { if (obj == null) obj = new SingletonDemo (); return obj; } } Fill in the blanks above so that the class is singleton.
Options:
a. Static, private, SingletonDemo
b. Private, SingletonDemo, static
c. Private, static, SingletonDemo
Reveal Answer
47. Does Garbage Collection disposes a object even if you abort the application in the middle?
Options:
a. Yes
b. No
Reveal Answer
48. Shadowing is:
Options:
a. To override the base class method
b. To provide a different implementation of base class sealed method
c. To overload the base class method
d. None of the above
Reveal Answer
49. If parameter/ local variable and data member of a class have same name, _______
Options:
a. The data member takes the precedence over local variable
b. The local variable takes the precedence over data member
c. Not valid
Reveal Answer
50. ________ is used to initialize the static/ shared member dynamically and is executed when the class is loaded.
Options:
a. Constructor
b. Shared constructor
c. Static constructor
d. None of the above
Reveal Answer
51. Which of these methods are used instead of a Finalize method?
Options:
a. Close
b. Dispose
c. Both a & b
d. None of the above
Reveal Answer
52. Late Binding refers to a call that
Options:
a. Decides if a method exists at runtime
b. Decides if a method exists at compile time
c. Decides if a method exists once the class is instantiated
d. None of the above
Reveal Answer
53. Name the Top .NET base class that everything is derived from?
Options:
a. System.object
b. System.Data
c. System.web
Reveal Answer
54. Compiler generates a type definition for the myClass, giving it a Name property as String and a Age property as int. This helps in late binding as well.An Anonymous type is ______
Options:
a. way to encapsulate a set of read-only properties into a single object
b. We can create anonymous types by using the new operator together with an object initialize
c. Type name is generated by the compiler
d. All of the above
Reveal Answer
55. Principal object is used for:
Options:
a. To represent authenticated users
b. To represent a cookie
c. To represent HttpContext object
d. None of the above
Reveal Answer
56. Access modifier are used to__________
Options:
a. Specify data type
b. specify the declared accessibility of a member or a type
c. specify size of the variable
d. the value of the variable
Reveal Answer
57. How many access modifiers available?
Options:
a. 4
b. 5
c. 3
Reveal Answer
58. An object has______
Options:
a. properties for validations
b. Methods for functionality
c. Events for depicting the change of state
d. All the above
Reveal Answer
59. Encapsulation is used to
Options:
a. Exhibit an object in different form with the same functionality
b. For the reusability of the code
c. Binding of data and behavior in controlled environment
Reveal Answer
Packages
Gold Membership
Microsoft Azure Suite &Suite Plus
Azure DevOps Expert &Expert Plus
MS.NET Foundation For Beginners
MS.NET Full Stack Developer
UI / Web Development
SQL Server & MSBI Tools
Software Testing
Resources
Blog
Deccansoft
AzureA2Z
Wall of Fame
On-Job Tech Support
About
About BestDotNetTraining
About Trainer
Testimonials
FAQ
Other links
About Us
Contact Us
Leave us a feedback
Sitemap
Privacy Policy
Terms & Conditions
Proudly Powered by