Showing posts with label Classes. Show all posts
Showing posts with label Classes. Show all posts

C# - Classes


You saw a class structure in the “Hello, C# World!” sample. In the C#, you define a class by using the class keyword, just as you do in C++. Following the class keyword the class name and curly brackets ({. . .}), as shown here:
class Hello
{
static void Main()
{
Console.WriteLine("Hello, C# World!");
}
}
Note: C# classes don’t end semicolon (;) as C++.
Once a class is defined, you can add class members to it. Class members can include constants, fields, methods, properties, indexers, events, operators, instance constructors, static constructors, destructors, and nested type declarations. Each class member has an associated accessibility, which controls the scope of the member and defines whether these members are accessible outside the class. 

Inheritance between Classes

An important feature of classes is inheritance. This allows us to create an object derived from another one, so that it may include some of the other's members plus its own. For example, we are going to suppose that we want to declare a series of classes that describe polygons like our CRectangle, or CTriangle. They have certain common features, such as both can be described by means of only two sides: height and base.
This could be represented in the world of classes with a class CPolygon from which we would derive the two referred ones: CRectanble and CTriangle ....LEARN MORE>>

Classes and Objects....cont(3)

Objects
The declaration of a class does not include objects of that class. It only specifies the type of information the objects of this class type will hold, when created. Objects of a class can be created using the class tag-name as type specifier. The syntax used to declare objects is:
class-name object1, object2, .....objectn;
Ads will appear onthe next page refresh.
For example:
class book;
{
public;
int bookno;
float cost;
LEARN MORE>>

Classes and Objects....cont(1)

An object is a region of storage with associated semantics. After the declaration int i;
we say that " i is an object of type int ". In C++, "object" usually menas "an instance of a class". Thus, a class defines the behaviour of many objects(instances). For example:
class Myclass
{
int a;
public;
void getval(int);
void display();
};
LEARN MORE>>

Classes and Objects

Introduction
A class is a fundamental building block of the object oriented programming language C++. Bjarne Stroustup, the originator of C++ language, gave the name "C with classes" to this language initially. The class is the most important feature of C++. It implements OOP concepts and ties them together.
A class is a way to bind data (describing an entity) and its associated functions together. In C++, a class makes a data type that is used to create objects of this same type.
The prerequisites for classes and objects are structures and the functions. A structure provides a way to group data elements and a function organizes program actions into a named entity.
Class Specification
A class specification consists of two parts:
1. Class declaration
2. Class method definition
Declaration of a Class
A class is declared using the class keyword. the syntax of a class declaration is similar to that of a structure.
The general form of a class declaration is : LEARN MORE>>