Pages

Monday, October 11, 2010

oops-interview-questions

Views

“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.

0 comments:

Post a Comment

 

Web Design Company karimnagar, Web Designing warangal, Logo Design Company nizamabad, Indian Website Design Company, maddysoft.co.in