“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
PublicProtectedFriendProtected FriendPrivate 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 OverRiding?
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.
Partial Classes Concept in Asp.Net 2.0One of the language enhancements in .NET 2.0 - available to both VB2005 and C# 2.0 programmersis support for partial classes. In a nutshell,
Partial classes mean that your class definition can be split into multiple physical files. Logically, partial classes do not make any difference to the compiler. During compile time, it simply groups all the various partial classes and treats them as a single entity.
Benefits of Partial Classes One of the greatest benefits of partial classes is that they allow a clean separation of business logic and the user interface (in particular, the code that is generated by the Visual Studio Designer). Using partial classes, the UI code can be hidden from the developer, who usually has no need to access it anyway. Partial classes also make debugging easier, as the code is partitioned into separate files. This feature also helps members of large development teams work on their pieces of a project in separate physical files.
Wednesday, December 24, 2008
OOPS - Access Specifiers
Posted by
sivashiva
at
2:11 AM
Subscribe to:
Post Comments (Atom)
16 comments:
thanks for the wonderful article. helped clear things out a lot!
[B]NZBsRus.com[/B]
Lose Laggin Downloads With NZB Files You Can Instantly Search Movies, Games, MP3 Albums, Software and Download Them at Flying Rates
[URL=http://www.nzbsrus.com][B]Usenet[/B][/URL]
kazar torebki
to torebki skórzane , torby listonoszki , torebki david jones . torebki listonoszki , torebki online ?
phone line dating canada http://loveepicentre.com/ kenyan dating
god words on dating http://loveepicentre.com/articles.php dating a sculpture
financial math ebook http://audiobookscollection.co.uk/de/Young-Person-s-Occupational-Outlook-Handbook/p110102/ ebook a book on c [url=http://audiobookscollection.co.uk/The-World-Bank/m123881/]free microsoft reader ebook[/url] adobe ebook 2.2 build 200
delphi ebook ar ivi http://audiobooksworld.co.uk/fr/Making-Meaning-Inference-and-Rhetoric-in-the-Interpretation-of-Cinema/p220820/ free scifi ebook poul anderson [url=http://audiobooksworld.co.uk/George-Samuel-Clason/m42853/]make your own ebook reader[/url] ebook palm linux
As Tad Crawford writes in The Artist-Gallery Partnership: a
Practical Guide to Consigning Art,. He says that he heard about it two months ago and Stassi and Jax were together then.
For a couple who has dated over the past three months, you're probably more inclined to kiss for longer, and our survey results agreed with most saying that a long kiss is completely appropriate.
Check out my web page - The Tao of Badass
Either I stop biting my nails, or she gives me a full refund.
The open wounded part can lead to an infection not only to your fingernails but
also in your mouth. Request loved ones and workmates to let you recognize when your arms
are in your mouth.
My web-site :: Nail biting
[url=http://certifiedpharmacy.co.uk/products/imitrex.htm][img]http://onlinemedistore.com/10.jpg[/img][/url]
pharmacy rep jobs http://certifiedpharmacy.co.uk/products/accutane.htm america pharmacy association [url=http://certifiedpharmacy.co.uk/products/tretinoin-cream-0-05-.htm]ferris state pharmacy[/url]
how to compound suspension from tablets and pharmacy http://certifiedpharmacy.co.uk/categories/anti-allergic-asthma.htm carolina columbia cvs pharmacy south [url=http://certifiedpharmacy.co.uk/products/flagyl-er.htm]flagyl er[/url]
cvs pharmacy corporate http://certifiedpharmacy.co.uk/products/cefixime.htm pharmacy lp blank labels [url=http://certifiedpharmacy.co.uk/products/precose.htm]pharmacy technician find a job[/url]
nogales sonara pharmacy http://certifiedpharmacy.co.uk/products/rocaltrol.htm on line pharmacy canada [url=http://certifiedpharmacy.co.uk/products/viagra-professional.htm]viagra professional[/url]
I can't tell you how fast you will see results because it depends on how much you want to get rid of acne. In order to reassure yourself that your moles are safe from cancer, you would have to reinforces your observation by a doctor's diagnosis.
Others think tanning and sunning themselves will dry up their skin and pimples
to eliminate their acne.
Here is my homepage - How to get rid of warts
These oils have been tested and proven to be effective against a variety of
warts. Individuals who have suffered with acne look forward
to the day when they can look in the mirror and see skin that is pimple and blemish-free.
This sounds drastic but as long as you pay due care and attention when carrying
the task out the removal should happen without a hitch.
Also visit my web page ... http://skintagremover12b.webs.com
These oils have been tested and proven to be effective against a variety of warts.
Individuals who have suffered with acne look forward to the day when they can look in the
mirror and see skin that is pimple and blemish-free. This sounds drastic but as long as you pay due care and
attention when carrying the task out the removal should happen without a hitch.
Here is my site http://skintagremover12b.webs.com
[url=http://certifiedpharmacy.co.uk/products/aricept.htm][img]http://onlinemedistore.com/7.jpg[/img][/url]
nova pharmacy http://certifiedpharmacy.co.uk/products/baclofen.htm syntrom pharmacy [url=http://certifiedpharmacy.co.uk/products/emsam.htm]university of connecticut school of pharmacy[/url]
sams pharmacy in inaianapolis http://certifiedpharmacy.co.uk/products/vermox.htm pharmacy assistant courses sydney [url=http://certifiedpharmacy.co.uk/products/cardura.htm]cardura[/url]
salary of pharmacy tech http://certifiedpharmacy.co.uk/products/accutane.htm pca pharmacy mediq prn west chester oh [url=http://certifiedpharmacy.co.uk/categories/cholesterol.htm]save mart pharmacy porterville[/url]
fast online pharmacy percocet http://certifiedpharmacy.co.uk/products/gift-kamagra-jelly.htm pharmacy oakland [url=http://certifiedpharmacy.co.uk/products/aleve.htm]aleve[/url]
It is caused by the hormonal problems, weight gain, and many other factors.
It contains natural ingredients like olive oil, jojoba oil, and other essential
oils. There may be a new and innovative cellulite treatment available now: cryotherapy.
Also visit my blog :: how to get rid of cellulite on thighs
amanda loncar dating http://loveepicentre.com is nick dating selena gomez
stages of dating [url=http://loveepicentre.com/success_stories/]rabbit tv dating[/url] is lyssa chapman dating someone
gay and lesbian dating [url=http://loveepicentre.com/map/]100 dating sites in country[/url] new york city executive dating service [url=http://loveepicentre.com/user/Slava/]Slava[/url] bensonhurst dating game
Post a Comment