Tuesday, 31 May 2011

abstract & interface

If I am designing something which is related with non related classes we go for interface
If we are developing class which is related with hirarecy of classes at that time we go for abstract
example of interface : payment gateways
example of abstract : bird class with aeroplane class

Tuesday, 26 April 2011

Can a method be overloaded based on different return type but same argument type ?

No, because the methods can be called without using their return type in which case there is ambiguity for the compiler.

Monday, 19 July 2010

Constructors in C#

http://www.c-sharpcorner.com/UploadFile/puranindia/LearningConstructorsInC-sharp05182009044452AM/LearningConstructorsInC-sharp.aspx

Wednesday, 14 July 2010

polymorpihsm

polymorpihsm ->one name, many form.

have 2 types : 1. Compile time, 2 Run time

1 compile time: also called overloading
have 3 types. 1. Constructor overloading(i.e.,with same constructor name and different no of arguments or different datat types or both ) 2 Function overloading(i.e.,with same function name and different no of arguments or different datat types or both)

3. operator overloading: exaample : String s = "James";

s = s + "Bond";

Runtime poly: is achieved by overridding parent class method:

This is called Dynamic method dispatch.


1. function overloading,

2. Runtime polymorphism --Using Interface reference,

EX:
interface name I ,abstract Method();
implimenting classes A,B

ref I;
objA= new A();
objB= new B();

runtime
objA=I

objA.Method();

objB=I;
objB.Method();

Tuesday, 6 July 2010

Can we call a base class method without creating instance?

Its possible If its a static method.
Its possible by inheriting from that class also.
Its possible from derived classes using base keyword.

You have one base class virtual function how will call that function from derived class?

class a
{
public virtual int m()
{
return 1;
}
}
class b:a
{
public int j()
{
return m();
}
}


Class a
Public Overridable Function m() As Integer
Return 1
End Function
End Class
Class b
Inherits a
Public Function j() As Integer
Return m()
End Function
End Class

Thursday, 17 June 2010

SHADOWING

When global and local varible in the same name.
the local varibale in a mehod or function which use to
override the global is called the shadowing.
ie the Global varible is being shadowed by the
local varible


Public Class Clsparent
Public x As String = 7

End Class

Public Class ClsShadowedparent
Inherits Clsparent
Public Shadows x As String = "dgfdg"

Sub kotha()
Dim k As Integer = MyBase.x
Dim kk As String = Me.x
End Sub
End Class



button_click :
============

Dim ksf As New ClsShadowedparent
ksf.kotha()




Thre are few differences between those.
1. Shadowing is bad programming practice according to OOPs concepts.
2. In shadowing signature could be different.
3. In Shadowing both Derived class methods and Base Class methods are available for use.(So its a bad practice)