what is the difference between class and objects?
Sri Chandra
Select an image from your device to upload
Hi,
If you have sub class version method too, then need to elaborate the design by adding one interface which will hold all of your such methods, like below. This design can apply to any of your sub class by just implementing this interface.
public
{
//Subclass version will be called
ICommon obj = new MyAbstractChild();
obj.MyAbstractMethod();
//Main abstract class version will be called
MyAbstract obj1 = new MyAbstractChild();
obj1.MyAbstractMethod();
}
public new void MyAbstractMethod()
Console.WriteLine("I am abstract child");
public abstract class MyAbstract : ICommon
CLASS is a user defined data type and store in heap. two types of data type value types and reference typew . in value types stored in stack and when we defined user defined data type it actually store the memory address. and classes gives resuablity security and code access security.
and when we create the class when we declare object memory is allocated to this variable. so when we create the class of an object it is object is instiated by new operator.
A Class is collection of attributes(fields) and methods and this methods works on the data. The enitre class is encapsulated and is represented as a single unit. But again Class is a model only that describes about how class methods works on the class attributes.
When this class takes the shape of a real world thing, that time we say the class exists and we called it as Object. So Objects are real life implementation or programmatically instatiation of the Class.
For Example, Shape may be a class and Triange and Square are objects. We can take "Side" as a field and "Area" as a method. So Area takes the Side and calculates the Area of that particular shape.