Interface
|
Abstract class
|
we can not declare a static method in an interface, because
interfaces have no implementation.
xxxxxx
public interface Iproduct
{
static void test();
}
xxxxx
|
declare a method as static
in an abstract class,
because abstract classes can
have implementations of static
methods
ex: public static void test()
{
}
|
Thus by above point :interface cannot implement methods
|
abstract class can implement methods
|
An interface cannot contain fields,
constructors, or destructors and it has only the property's signature but no implementation.
|
An abstract class can contain fields, constructors, or destructors
and implement properties
|
Based on above point, we can say ,:Thus a class may inherit several
interfaces but only one abstract class.
|
|
A class implementing
an interface has to implement
all the methods of the interface
|
but the same is not required in the case of an abstract Class.
|
No access modifiers are allowed in Interface
|
Various access modifiers such as abstract, protected, internal,
public, virtual, etc. are useful in abstract Classes
|
Abstract
classes are faster than interfaces.
--------------------------------------
Sealed class
----------------------------------------
public sealed class classSealed
{
// Class members
here.
public string ID;
public double Price;
}
-------------------------------------------------------------------------------------------------
A sealed class cannot be used as a base class.
For this reason, it cannot also be an abstract class.
Sealed classes are primarily used to prevent derivation.
Because they can never be used as a base class, some run-time optimizations can make
calling sealed class members slightly faster.
Sealing a method means one cannot override it.
In C# structs are implicitly sealed; therefore, they
cannot be inherited.
Ex:Humanàmale
class,female class(Here we can say male and female classes are sealed)
public class TestClass : classSealed
{
}
In C# a method can not be declared as sealed.
However when we override a method in a derived class, we can
declare the overridden method as sealed as shown below.
By declaring it as sealed, we can avoid further overriding of this method.
public class testClass
{
public int x;
public int y;
public virtual void
testMethod(){
}
}
public class
TestClass: testClass
{
public override sealed void testMethod(){
}
}
-------------------------------------------------------------------------------
Prove that only 1 instance of the object is created for static classes?
static constructor:only one 1 instance of the object is created then this constructor should run only once.
Static class:we can define static memebers(like public static int icount)
if we invoked the method twice/but constructor will fire only once.
public static class Staticclasses
{
public static int icount;
static Staticclasses()
{
}
static void somemethod()
{ }
}
What is the use of private constructor ? This is used for utility classes
1.a class with a private constructor can not be inherited
2. we can not create a object of the class which has private constructor
3. many times we do not want to create instances of certain classes like utility ,common routine classes
public class class1
{
private class1()
{
}
public static string getdata()
{
return "hello"
}
}
Client can use by using:
string str=class1.getdata() (SO we are not create instance,we can access method)
Can we define abstract class as a static?
never forget we can never define abstract class as static
What is the use of c# (Csharp) Shadowing ?
shadowing is replaces current element of the parent where as override is replace the implementations(it does not replace data type or (datatype /datamethod)
Abstraction_Encapsulation:
namespace Abstract_encapsulation
{
public class customer
{
//step1:what does customer(Abstraction)//show only what is neccessary
//step2:How(Validate, createdbobjects)
//step3:made complicated method as private (Encapuslation):means reduce the complexity/hide complexity to client
public string customercode = "";
public string customername = "";
//public void Add()
//{
//}
//Granular
//public bool validate()
//{
// //cust code and name
// return true;
//}
//public bool createDbobjects()
//{
// return true;
//}
//Now simplified to expose to clients
public void Add()
{
validate();
createDbobjects();
}
private bool validate()
{
//cust code and name
return true;
}
private bool createDbobjects()
{
return true;
}
}
}
Great content thanks for sharing this informative blog which provided me technical information keep posting.
ReplyDeleteaws training in chennai | aws training in annanagar | aws training in omr | aws training in porur | aws training in tambaram | aws training in velachery
It’s great to come across a blog every once in a while that isn’t the same out of date rehashed material. useful one!!
ReplyDeleteandroid training in chennai
android online training in chennai
android training in bangalore
android training in hyderabad
android Training in coimbatore
android training
android online training
Informative blog! it was very useful for me.Thanks for sharing. Do share more ideas regularly.
ReplyDeletejava training in chennai
java training in tambaram
aws training in chennai
aws training in tambaram
python training in chennai
python training in tambaram
selenium training in chennai
selenium training in tambaram
Your post helped me to understand the future and career prospects & Keep on updating your blog with such awesome article.
ReplyDeletejava training in chennai
java training in annanagar
aws training in chennai
aws training in annanagar
python training in chennai
python training in annanagar
selenium training in chennai
selenium training in annanagar
Your post helped me to understand the future and career prospects & Keep on updating your blog with such awesome article.
ReplyDeletesap training in chennai
sap training in omr
azure training in chennai
azure training in omr
cyber security course in chennai
cyber security course in omr
ethical hacking course in chennai
ethical hacking course in omr
I, Greet this Tutorial is just awesome. It is really helpful for a newbie like me. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. The people to give them a good shake to get your point and across the command.
ReplyDeleteAws Training in Chennai
Aws Training in Velachery
Aws Training in Tambaram
Aws Training in Porur
Aws Training in Omr
Aws Training in Annanagar