.net/asp.net training for MSC IT Freshers in Cegonsoft Bangalore | Chennai | Coimbatore
Class:
A class is a concept that lets you create custom types by combining other variables, methods and events. A class is like a plan. It defines the data and the behavior of a type. If the class is not declared as static, the client code can be used by creating objects or situations that are assigned to a variable. The variable remains in memory until all references to it out of reach. At that time, the CLR brand as eligible for garbage collection. If the class is declared as static, only one copy in memory and the client code can only be accessed by the class itself is not an instance variable.
Declaring Classes
Classes declared using the class keyword.
public class Person
/ / Fields, properties, methods, and events here …
The class keyword is preceded by the level of access. Because the public is used in this case, anyone can create objects of this class. The name of the class follows the class keyword. The rest of the definition is the body of the class, which defines the behavior and data. Fields, properties, methods and events in a class are collectively known members of the class.
Creating objects
Although sometimes used interchangeably, a class and an object are two different things. A class defines an object type, but it is not an object itself. An object is a specific device based on a class, and is sometimes called an instance of a class.
Objects can be created using the new keyword followed by the name of the class that the object is based, like this:
Personal object1 = new Person ();
Class Inheritance
Inheritance is through a referral, which means that a class is declared using a base class which inherits data and behavior. A base class is specified by adding a comma and the base class name after the name of the derived class, for example:
public class Office: Employee
Fields / / employee, properties, methods and events are inherited
/ / Fields new office, properties, methods and events here …
A class can be declared abstract. An abstract class contains abstract methods that define a signature but no implementation. Abstract classes can not be instantiated. They can be used by derived classes that implement the abstract methods. By contrast, is a closed class does not allow other classes to be learned.








Posted in
Tags: