OOPs Interview Questions

“The ability to define a class and create instances of classes is one of the most important capabilities of any Object Oriented Language”

 

Q: How will you define a CLASS ?

A: All classes in Visual Basic. NET are defined in a .VB file (as oppose to .CLS file in vb6), Also .VB file may contain one or more classes. The basic syntax of a class is as follows:

 

Class ClassName

 

End Class

 

Public|Protected|Friend|Protected Friend|Private Class Vehicle

 

End Class

 

Q: List All Class Access Specifiers?

A: There are five access specifiers in Visual Basic .NET defined as follows:

 

  • Public – Applied at the class level and is the most common specifier. Public Classes are classes that are intended to be used by any consumer.

     

    Public Class PubClass

End Class

 

  • Protected – can only be applied to Nested Classes. Are only accessible within the class and within the child classes.

 

Public Class HasProtected

Protected Class ProtectedClass

 

End Class

End Class

 

  • Friend – Are accessible only within the program in which they are defined. If you add the Friend access specifier to a class definition, instance of that class can only be created from within th same program.

 

Friend Class FriendClass

Public Shared Sub PublicMethod()

MsgBox(“FriendClass.PublicMethod”)

End Sub

End Class

 

  • Protected Friend – Represents a union of the Protected and Friend Specifiers. Protected class must be nested class, thus Protected Friend class must be nested too.

 

Public Class HasProtectedFriend

Protected Friend Class ProtectedFriend

Public Shared Sub Test()

MsgBox(“test”)

End Sub

End Class

End Class

 

  • Private – Can only be applied to a nested class. A Private nested class represents implementation details of the class. When you have complex problem that requires more problem solving horsepower then simple methods can provided, defining a nested private class that implements the abstraction.

 

Public Class HasPrivate

Private Class PrivateClass

 

End Class

End Class

 

Q: What is a Field?

A: Field is a Data Member of a class. Fields can be ValueType members, like Integer or Dates, or can be aggregate types, like structures or classes.

 

Q: What is a Property?

A: A Property is a special member constructor that is used like a field, but acts like a method. Properties are special kind of methods that generally are used to provide constrained access to Field.

 

Q: What are the Indexed Properties?

A: Indexed Properties are simply property methods that have a mandatory parameter. The mendatory parameter is semantically treated like an index Index properties has an argument between the parentheses. This argument doesn’t represent the field value; rather, it represents an index to an underlying field value. The fundamental idea behind indexed properties is that you can wrap arrays and other kind of collections of data safely behind property methods.

 

Public Class Indexed

Private FStrings() As String = {“One”, “Two”, “Three”}

 

Public Property Strings(ByVal index As Integer) As String

Get

Return FStrings(index)

End Get

Set(ByVal value As String)

FStrings(index) = value

End Set

End Property

End Class

 

‘//useage

‘Msgbox(objIndex.Strings(1))

 

Q: Explain Default Properties?

A: Default Properties must be indexed properties, you can have only one default property per class and you can invoke property setter and getter methods on a default property using the verbos or shorthand form.

 

Public Class Indexed

Private FStrings() As String = {“One”, “Two”, “Three”}

 

Default Public Property Strings(ByVal index As Integer) As String

Get

Return FStrings(index)

End Get

Set(ByVal value As String)

FStrings(index) = value

End Set

End Property

End Class

 

‘//useage

‘Msgbox(objIndex.Strings(1))

‘Msgbox(objIndex(1)

 

Q: What are ReadOnly, WriteOnly and Shared Properties?

A: Read Only property is a property that can be used as an r- value only. That’s why a property statement that includes a read only modifier will generate a getter block only and users can evaluate this property but can not modify it.

 

Public ReadOnly Property Strings(ByVal index As Integer) As String

Get

Return FStrings(index)

End Get

End Property

 

Write Only – is a property that a consumer can modify but can’t view. This implements a property setter only.

 

Public WriteOnly Property Strings(ByVal index As Integer) As String

Set(ByVal value As String)

FStrings(index) = value

End Set

End Property

 

Shared Property – is a property that a shared members can also be invoked using instances.

 

Public Property Strings(ByVal index As Integer) As String

Get

Return FStrings(index)

End Get

End Property

 

Q: What is Constructor and Destructor ?

A: A constructor is called to Initialize a class. A destructor is called to Finalize the class. Visual Basic.NET implements the constructor as Sub New and Destructor as protected method Sub Finalize().

 

Q: what is MyBase and MyClass?

A: MyBase allows you to invoke methods in your class’s Base Class that may be overloaded in your class, resolving any name ambiguity.

 

MyClass is roughly equivalent to the Me reference to self.

 

 

Q: what is Method Overloading?

A: Method Overloading means to have two or more methods in the same class with different signature. The benefit of method overloading is that it allows you to implement methods that supports the same semantic operation but differ by argument number or type.

Public Overloads Sub GetCustomer(ByVal strCustomerName As String)

End Sub

 

Public Overloads Sub GetCustomer(ByVal iCustomerID As Integer)

End Sub

 

Q: what is Method OverRidingd?

A: Method Overriding changing the behavior of a method in a base class. Use keyword Overrides.

 

Q: what are Overridable, MustOverride and NotOverridable modifiers?

A: Overridable – modifier indicates that a method can be overriden.

NotOverridable- modifier indicates that you can not override a method.

MustOverride- modifier indicates that a method is abstract, and child class must implement the MustOverride method in a parent class.

 

Q: what Shadows modifier?

A: Shadows – if you want a child class to use a name previously used in a parent class, use the Shadows keyword to do so. Shadows keyword simply allows you to reintroduce a previously used name in the child class without a compiler error.


Download in word document oops-qa.doc

Ripal Maulik Soni

About these ads
Comments
12 Responses to “OOPs Interview Questions”
  1. John says:

    Hello Ripal Soni,

    First of all, http://www.ripalsoni.wordpress.com is an excellent site for .NET Interview Question Answers. Excellent OOP Question Answer for Vb.NET

  2. PREPARING .NET???
    PLANNING A .NET INTERVIEW???
    CHECKOUT –>

    http://www.dotnetuncle.com

    FIND THE LATEST ASP.NET, C#, VB.NET, OOPS, .NET Framework INTERVIEW QUESTIONS
    ALL QUESTION-ANSWERS FREE!!!
    FIND ANSWERS TO ALL YOUR .NET QUESTIONS…
    OVER NEW 100 SHORT-ANSWER .NET INTERVIEW QUESTIONS RECENTLY ADDED!!!

  3. raju jana says:

    I am pleased with your effort and mind set for helping us.

    Wish you very good luck from my hearts.

  4. chandu says:

    very good site

  5. Mayank Goswami says:

    Good work.
    Will be more helpful if additional questions, related to interfaces and abstract classes, are added.

  6. Sonu says:

    Very Nice…

  7. Naga says:

    Here u can get all asp.net,C#.net,sql server
    ado.net interview question with answers
    sp.net,C#.net,sql server
    ado.net interview question with answers

  8. Ravi Ranjan karn says:

    gud

  9. yerroju says:

    Great Work…Go On

  10. thara says:

    Thank You allll………..Very Helpul for freshers like me

Trackbacks
Check out what others are saying...
  1. […] OOPs Interview Questions […]



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 27 other followers

%d bloggers like this: