Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
69 views

Object Oriented Programmings Interview Questions & Answers PDF

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views

Object Oriented Programmings Interview Questions & Answers PDF

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 53

.

Net OOPS InterView Questions and Answer with Practical


.Net OOPS InterView Questions and Answer with Practical
Different .Net Versions?
Prior to Visual Studio Version 4.0, there were V Visual C++,visual Basic 3, Visual FoxPro and
Visual SourceSafe as separate products.
SNO Product Name Product Version Release Date CLR Version .Net Version WCF Version

1. Visual Studio 4.0 4.0 April 1995 N/A N/A N/A

2. Visual Studio 97 5.0 Feb 1997 N/A N/A N/A

3 Visual Studio 6.0 6.0 June 1998 N/A N/A N/A

4. Visual Studio .NET (2002) 7.0 Feb 13, 2002 1.0 1.0 N/A

5. Visual Studio .NET 2003 7.1 April 24, 2003 1.1 1.1 N/A

6. Visual Studio 2005 8.0 Nov 7, 2005 2.0 2.0 N/A

7. Visual Studio 2008 9.0 Nov 19, 2007 2.0 3.0 & 3.5 3.0

8. Visual Studio 2010 10.0 April 12, 2010 4.0 4.0 4.0

9. Visual Studio 2012 11.0 Sep 12, 2012 4.0 4.5 4.5

10. Visual Studio 2013 12.0 Oct 17, 2013 4.0 4.5.1 4.5

11. Visual Studio 2015 14.0 July 20, 2015 4.0 4.6 4.5
.Net OOPS InterView Questions and Answer with Practical

.Net OOPS Part 1: (Youtube Link)

● What is .Net framework? Different Versions of .Net?


● What is latest .Net framework and Vs available?
● What is OOPS?
● Important OOPS concepts?
● What is Class and how to declare the class?
● What is object and how to declare the Object?
.Net OOPS InterView Questions and Answer with Practical
.Net Framework: .Net is network enabled technology
which provides the facility to develop, run and deploy
the .net based application. .Net also provides the
interoperability between different platform.

● .Net is developed by microsoft.


● To develop application we need visual studio, VS is
called IDE( integrated development environment ).
.Net OOPS InterView Questions and Answer with Practical
What is OOPS: It is known as object oriented
programming language. OOPS mainly works on classes
and objects.

Important Concepts of OOPS:


● Class
● Objects
● Inheritance
● Polymorphism
● Abstraction
.Net OOPS InterView Questions and Answer with Practical
What is Class: A class is a construct that enables you to
create your own custom types by grouping together
variables of other types, methods and events. A class is
like a blueprint. It defines the data and behavior of a
type.
syntax of class:
Access modifier class Keyword ClassName
{
}
E.g.
.Net OOPS InterView Questions and Answer with Practical
What is Object: An object is basically an instance of
class. It allocated the memory to access the members of
class.

Syntax for object:


ClassName objectname = new ClassName();
e.g. Employee emp = new Employee();
.Net OOPS InterView Questions and Answer with Practical
.Net OOPS Part 2: (Youtube Link)

7. What are naming convention for class in .net?


8. Can we create class name with numbers?
9. Can we use special character to create the class?
10. By default class follows which access modifier?
11. Types of Access specifier/modifiers
.Net OOPS InterView Questions and Answer with Practical
Access Modifier/Specifier:

1. Public: Accessible in any project.


2. Private : Members can be accessed in same class
only.
3. Internal: Same project, same library ,same assembly
only.
4. Protected: Only available in child class.
5. Protected Internal: it is protected + Internal.
.Net OOPS InterView Questions and Answer with Practical
.Net OOPS Part 3: (Youtube Link)

12. Can we declare class as private/protected/protected


internal? No
13. By default class members are, means access
modifier? : Private
14. Diff bw Public, Private and Internal access modifier?
.Net OOPS InterView Questions and Answer with Practical

● By default members of class are private. Means they


can only be accessed within class only.
.Net OOPS InterView Questions and Answer with Practical
Access Modifier/Specifier:

1. Public: Accessible in any project.


2. Private : Members can be accessed in same class
only.
3. Internal: Same project, same library ,same assembly
only.
4. Protected: Only available in child class.
5. Protected Internal: it is protected + Internal.
.Net OOPS InterView Questions and Answer with Practical

● By default members of class are private. Means they


can only be accessed within class only.
.Net OOPS InterView Questions and Answer with Practical
.Net OOPS Part 4:

15. Difference between protected and protected


internal in .net c#?
.Net OOPS InterView Questions and Answer with Practical
SNo Protected Protected Internal
1. Access is limited to the containing Access is limited to the current
class or types derived from the assembly or types derived from
containing class. the containing class.
2. This can be accessed within same This can also be accessed within
project as well as outside the project same as well as outside the
project but also can be accessed
as internal.
3. The protected member can not be Protected member can be
accessed by creating the object of accessed by creating the object in
class. same project only.
4. It behaves like Protected +
internal.
.Net OOPS InterView Questions and Answer with Practical
.Net OOPS Part 5:

16. By default class members/fields are? (Access


modifier) : Private
.Net OOPS Interview Questions and Answer with Practical
.Net OOPS Part 6:
17. Is it necessary to have Main method in console
application?: yes
What is entry point in console application?
18.Compile time error or runtime error: compile error
19. Is it necessary to have parameter in Main method?:
No
20 . Can we have 2 Main method?
21.Can we have Main method in some other class?yes
.Net OOPS Interview Questions and Answer with Practical
.Net OOPS Part 7:
22. What is inheritance?: code reusability.
23. What is base/parent and child/derived class.
CP : child/ Derived always left side and P Parent/base
right
24. How to reuse inherited members in child class?
Directly we can write the parent member.
25. Does c# supports multiple inheritance?: no
26. How to achieve multiple inheritance?: Interface
.Net OOPS InterView Questions and Answer with Practical
Inheritance: One of the most important concepts in
object-oriented programming is inheritance. Inheritance
allows us to define a class in terms of another class,
which makes it easier to create and maintain an
application. This also provides an opportunity to reuse
the code functionality and speeds up implementation
time.
.Net OOPS Interview Questions and Answer with Practical
.Net OOPS Part 8:

27. Why c# does not support multiple inheritance?


28. Is circular inheritance possible ? A:B, and B:A: no
29. How do you prevent a class from being inherited ?
30. What is Sealed keyword?
31. Can we create the object of Sealed class? : yes
32. Can derive class have public modifier when there are
no modifiers specified on the base class? : No
.Net OOPS InterView Questions and Answer with Practical
● Diamond/ Ambiguity : When 2 classes have same
method then child class will be confused which
method to refer.

● Sealed Class: The sealed modifier is used to prevent


derivation from a class. An error occurs if a sealed
class is specified as the base class of another class.
.Net OOPS Interview Questions and Answer with Practical
.Net OOPS Part 9:
33. Can we mark methods as Sealed?
34. what do you mean by upcasting and downcasting ?
BaseClass b = new BaseClass() ?
BaseClass b = new ChildClass() ?
ChildClass c = new ChildClass() ?
ChildClass c = new BaseClass() ?
BaseClass b = new BaseClass() ?
ChildClass c = (ChildClass) b BaseClass b = new ChildClass() : both
have Test() b.Test(); Base or child method will be called?
.Net OOPS InterView Questions and Answer with Practical
● Upcasting : assigning a derived class object to a base
class.This is implicit. BaseClass b= new DerivedClass.
● Downcasting: assigning base class object to derived
class. This is explicit and it throws runtime error .
● BaseClass b = new BaseClass() : will work
● BaseClass b = new ChildClass(): will work
● ChildClass c = new ChildClass(): will work
● ChildClass c = new BaseClass(): compile time error
● BaseClass b = new BaseClass()
ChildClass c = (ChildClass) b : RunTime error
.Net OOPS Interview Questions and Answer with Practical
.Net OOPS Part 10:
35. What is interface?
36. By default interface is? : Internal
All methods are by default public in interface.
37. Can we have access modifier in interface? : no
38. Can we have variables/Fields in interface? : No
39. Can we create instance of interface? : No
40. Can we create constructor in interface?: No
41. Can we declare properties in interface?: Yes
.Net OOPS InterView Questions and Answer with Practical
● Interface: An interface contains only the signatures
of methods, properties, events or indexers. A class or
struct that implements the interface must implement
the members of the interface that are specified in the
interface definition.
.Net OOPS Interview Questions and Answer with Practical
.Net OOPS Part 11:
44. How to achieve multiple inheritance through
interface?
45. If 2 interface has same method then how to
implement the method?
46. What is implicit implementation and when to use in
interface? : direct implementation
47. What is explicit implementation and when to use?
48. Is it compulsory to implement all methods of
.Net OOPS Interview Questions and Answer with Practical
.Net OOPS Part 12:

49. How to call interface implemented methods from


class?

50. How to call explicit implemented methods of


interface?
.Net OOPS Interview Questions and Answer with Practical
.Net OOPS Part 13:

51. What is Constructor? Use of constructor?

52. Different types of constructor?

53. What is Default constructor?


.Net OOPS InterView Questions and Answer with Practical
● Constructor: Constructor is a special method of a
class which will invoke automatically whenever
instance or object of class is created. Constructor
name should match with class and constructor does
not have any return type
● Constructor Use: Constructors are responsible for
object initialization and memory allocation of its
class. If we create any class without constructor, the
compiler will automatically create one default
constructor for that class. There is always at least one
.Net OOPS InterView Questions and Answer with Practical
Types of Constructor:
1. Default Constructor
2. Parameterized Constructor
3. Copy Constructor
4. Static Constructor
5. Private Constructor

Default Constructor :A constructor without having any


parameters called default constructor. In this
constructor every instance of the class will be initialized
.Net OOPS Interview Questions and Answer with Practical
.Net OOPS Part 14:
54. What is parameterized constructor?
55. Use of parameterized constructor?
56. What is constructor overloading?
57. Is it mandatory to have default and parameterized
constructor in class?
58. If we have only parameterized constructor, can we
create the object of class?
.Net OOPS InterView Questions and Answer with Practical
● Parameterized Constructor: A constructor with at
least one parameter is called a parameterized
constructor.

● Constructor Use: The advantage of a parameterized


constructor is that we can initialize the values at the
time of creation of object of class.

● Constructor Overloading: The constructor with


different parameters is known as constructor
.Net OOPS Interview Questions and Answer with Practical
.Net OOPS Part 15:

59. What is copy constructor?

60. Purpose of copy constructor?


.Net OOPS InterView Questions and Answer with Practical
● Copy Constructor: A parameterized constructor that
contains a parameter of same class type is called as
copy constructor.

● Purpose of Copy Constructor: Main purpose of copy


constructor is to initialize new instance to the values
of an existing instance.
.Net OOPS Interview Questions and Answer with Practical
.Net OOPS Part 16:
61. What is private constructor?
62. Use/purpose of private constructor?
63. Can we have default and private constructor both in
class? No
64. Can we create the object of class if we have only
private constructor in class?: No
65. Can we inherit the class if we have only private
constructor in class?: No
.Net OOPS InterView Questions and Answer with Practical
● Private Constructor: A private constructor is with
private access modifier is known as private
constructor

e.g.

● Use/Purpose of Private Constructor: It is generally


used in classes that contain static members only. It is
.Net OOPS Interview Questions and Answer with Practical
.Net OOPS Part 17:
67. What is static constructor?
68. Can we have access modifier in static
constructor?:No
69. Can we pass parameters in static constructor?: No
70. How to call static constructor or when static
constructor is called?:
71. How many times we can call static constructor?:one
72. When we create instance of class, which constructor
is called first?: First static then default.
.Net OOPS InterView Questions and Answer with Practical
● Static Constructor: A constructor with static keyword
is known as static constructor.

e.g.

● Use/Purpose of Static Constructor: A static


constructor is used to initialize static fields of the
class and to write the code that needs to be executed
only once.
.Net OOPS Interview Questions and Answer with Practical
.Net OOPS Part 18:
75. How can we call one constructor from another in the same class ?
76. When we create instance of child class which constructor is first
called, child or Parent?: First parent/base, then child constructor
77. How to call explicitly base class constructor from child class?:base
78. Can we call base class parameterized constructor from child class
constructor?
79. If we have only parameterized constructor in base class, can we
create object of child class? : No
80. Default access modifier/specifier for constructor ? : Private
.Net OOPS Interview Questions and Answer with Practical
.Net OOPS Part 19:
81. What is destructor?
82. Can we have access modifier in destructor? : No
83. Can we have parameters in destructor?: No
84. How many destructor we can have in one class? : one destructor
85. Can we define destructor in struct data type?: no
86. Do we have any control when destructor will be called?: no
87. Do we always need to implement the destructor?
88. When we define destructor, which method of garbage collector is
called? Finalize():
.Net OOPS InterView Questions and Answer with Practical
● Destructor: A destructor runs after a class becomes unreachable
It has the special "~" character in its name.

e.g.

● How to call destructor: The programmer has no control ove


when the destructor is called because this is determined by th
garbage collector. The garbage collector checks for objects that ar
no longer being used by the application. If it considers an objec
eligible for destruction, it calls the destructor (if any) and reclaim
.Net OOPS Interview Questions and Answer with Practical
.Net OOPS Part 20: (Polymorphism)
89. What is polymorphism?

90. Types of polymorphism?

91. What is method overloading? Example of method Overloading?

92. When we should use method overloading?

93. What are different names used for method overloading?


.Net OOPS InterView Questions and Answer with Practical
● Polymorphism: Polymorphism means one name many forms.

● Type of Polymorphism:
1. Overloading: Having different methods with same name but
different parameters in a single class is called method overloading.

2. Overriding: An override method provides a new implementation of


member that is inherited from a base class. The method that i
overridden by an override declaration is known as the overridden
base method. The overridden base method must have the sam
signature as the override method.
.Net OOPS InterView Questions and Answer with Practical
● When we should use Polymorphism: When you need couple o
methods to take different parameters but do the same thing.
e.g SearchEmployee(string fname)
SearchEmployee(string fname, string lname)

● Method overloading is also known as Early binding, compile time


and static.
.Net OOPS Interview Questions and Answer with Practical
.Net OOPS Part 21: (Polymorphism)
94. What is method overriding?
95. How to achieve method overriding?
96. Is it mandatory to implement virtual method of base class in child
class?: No
97. Can we override non-virtual method? : No
98. Can we use the virtual modifier with the static, abstract, private or
override modifiers. : No
99. Can we use virtual for internal, protected and protected internal?:
Yes
100. What are different names/terms used for overriding:
Dynamic, Runtime and Late binding
.Net OOPS InterView Questions and Answer with Practical
1. Method Overriding: An override method provides a new
implementation of a member that is inherited from a base class. Th
method that is overridden by an override declaration is known as th
overridden base method. The overridden base method must hav
the same signature as the override method.
.Net OOPS Interview Questions and Answer with Practical
.Net OOPS Part 22: (Polymorphism)
101. If parent class virtual method and child have same method
without override keyword, Will code be compiled? : yes code will be
compiled.
102. In above case which error/warning will be shown?
103. What is “new” keyword in method overriding?: method hiding
104. When to use “new” keyword in method overriding?
105. What’s the difference between new and override keyword?
106. Can we allow a class to be inherited but prevent method to be
overridden? : yes when method is override, sealed
107. What is Params keyword?
108. How to achieve method overloading through Params?
.Net OOPS InterView Questions and Answer with Practical
Method Hiding: We can predefine the method of parent class in child
class by implementing the concept of method hiding. In method hidin
the base(parent) class method is predefined in child class by specify new
keyword.

New and Virtual keyword: New keyword completely hides the base clas
implementation and creates a new method.It can be concluded that th
method defined is independent of base class method.
Override keyword overrides the base class implementation. it helps in
existence of different versions of method and appropriate version i
called dynamically.Objects of derived class will be calleed this method
instead of base class method.
.Net OOPS Interview Questions and Answer with Practical
.Net OOPS Part 23: (Abstract Class)

110. What is abstract class?


111. What is the syntax of abstract class?
112. What is the abstract method?
113. Can we declare abstract method as private? : NO
114. Can we create instance of abstract class? : No
115. Can abstract class inherit another class? : Yes
116. Can abstract class inherit interface? : Yes
117. Can abstract class have constructor? : Yes
.Net OOPS InterView Questions and Answer with Practical
Abstract class: Abstract class can have abstract as well as non abstrac
method. Abstract class behaves like interface as well as class.
.Net OOPS Interview Questions and Answer with Practical
.Net OOPS Part 24: (Abstract Class)

118. Can we declare Abstract class as static?

119. Can we declare Static methods in abstract class?

120. Difference between Abstract class and interface?(Most imp)


.Net OOPS InterView Questions and Answer with Practical
Difference between Abstract class & Interface:
SNO Feature Interface Abstract Class

1. Multiple Inheritance A class may inherit several interfaces. A class may inherit only one abstract class.

2. Default implementation An interface cannot provide any code, An abstract class can provide complete,
just the signature. default code and/or just the details that have
to be overridden.

s 3 Access Modfiers An interface cannot have access An abstract class can contain access
modifiers for the subs, functions, modifiers for the subs, functions, properties
properties etc everything is assumed
as public

4. Fields and Constants Interface can not have Fields and Abstract class can have fields and constants.
Constants

5. Constructor Interface can not have constructor Abstract class can have constructor

6. Static method Interface can not have static methods Abstract class can have static methods.
.Net OOPS Interview Questions and Answer with Practical
.Net OOPS Part 25: (Abstract Class)

121. Can we declare Abstract class as static?

You might also like