Professional Documents
Culture Documents
PRANAB BHATTACHARYA
MCA-TY Roll no. : 14
Overview
Classes and objects
Class members
Methods
Constructors
Destructors
Nested Classes
Access Modifiers and Access levels
Static (Shared) Classes and Members
Anonymous types
Inheritance
Overriding members
• Sealed and Abstract classes
Interfaces
1
o .NET Framework languages provide full support for
Object-oriented programming
o Encapsulation, Inheritance, Polymorphism
o Encapsulation means that a group of related
properties, methods, and other members are treated as a
single unit or object.
o Inheritance describes the ability to create new
classes based on an existing class.
o Polymorphism means that you can have multiple
classes that can be used interchangeably, even though
each class implements the same properties or methods
in different ways. 2
o Classes describe the type of objects…
o …while objects are usable instances of classes.
o Using the blueprint analogy, a class is a
blueprint, and an object is a building made from
that blueprint.
To define a class and object:
class SampleClass
{
}
SampleClass SC1 = new SampleClass();
3
o A method is an action that an object can perform.
class SampleClass
{
public int sampleMethod(string sampleParam)
{
// Insert code here
}
}
4
o A class can have several implementations, or
overloads, of the same method that differ in the
number of parameters or parameter types.
oTo overload a method:
public int sampleMethod(string sampleParam) {};
public int sampleMethod(int sampleParam) {}
Public int sampleMethod(int param1,int param2){};
7
o A class defined within another class is called nested.
(Default - private)
class Container
{
class Nested
{
// Add code here.
}
}
Console.WriteLine(SampleClass.SampleStrin
g);
oWhat is Overriding ??
15
Overriding modifiers..
C# Modifier Definition
virtual (C# Reference) - Allows a class member to be
overridden in a derived class.
16
o Interfaces, like classes, define a set of
properties, methods, and events.