SlideShare a Scribd company logo
5
Most read
7
Most read
9
Most read
TYPES OF CLASSES
4/30/2019 1
Definition:
 A class is a construct that enables you to create your own custom types by
grouping together variables of other types, methods and events.
 A class is like a blueprint. It defines the data and behavior of a type.
 When you define a class, you define a blueprint for a data type. This doesn't
actually define any data, but it does define what the class name means, that is,
what an object of the class will consist of and what operations can be
performed on such an object. Objects are instances of a class. The methods and
variables that constitute a class are called members of the class.
Declaration :
Classes are declared by using the class keyword, as shown in the following
example:
<access_specifier> class <class_name>
{
//Fields, properties, methods and events go here...
}
4/30/2019 2
Types of Classes
 Concrete Class
 Abstract Class
 Partial Class
 Sealed Class
 Static Class
 Nested Class
4/30/2019 3
Abstract Class
 An Abstract Class means that, no object of this class can be instantiated, but can
make derivation of this. It can serve the purpose of base class only as no object of
this class can be created.
Abstract Class is denoted by the keyword abstract.
 Use abstract when all sub-classes have to implement the method/property.
 Declaration of abstract class is :: abstract class absClass { }
 An abstract class can contain either abstract methods or non abstract methods.
Abstract members do not have any implementation in the abstract class, but the
same has to be provided in its derived class. Eg. of abstract methord —
abstract class absClass
{ public abstract void abstractMethod(); }
 Eg. of abstract class only with non abstract members.
abstract class absClass
{ public void NonAbstractMethod()
{ Console.WriteLine("NonAbstract Method"); } }
 An abstract class can be derived from another abstract class. In that case, in the
derived class, it is optional to implement the abstract method(s) of the base class.
4/30/2019 4
Example:
// Base abstract class
abstract class baseClass
{
public abstract int addNumbers (int a, int b);
public abstract int multiplyNumbers(int a, int b);
}
// Derived abstract class
abstract class derivedClass:baseClass
{
// implementing addNumbers…
public override int addnumbers (int a, int b)
{
return a+b;
}
}
// Derived class from 2nd class (derivedClass)
class anyClass: derivedClass
{
// implementing multiplyNumbers of baseClass…
public override int multiplyNumbers(int a, int b)
{
return a*b;
}
}
In the above example, we only implemented addNumbers in the derived abstract class (derivedClass). The
abstract method multiplyNumbers is implemented in the anyClass, which is in turn derived
from derivedClass.
4/30/2019 5
Partial Class
 This special type of class introduced with .Net Framework 2.0
 Partial Class allows its members – method, properties, and events
– to be divided into multiple source files.
 At compile time these files get combined into a single class.
 Partial Class is denoted by the keyword partial.
Do's and don'ts about partial class:-
• All the parts of a partial class must be prefixed with the keyword partial.
• Accessibility, signature etc. must be same in all parts of the partial class.
• You cannot seal one part of the partial class. In that case entire class in
sealed.
• If you define any part of the partial class abstract, entire class will
become abstract.
• Inheritance cannot be applied to a part of partial class. If you do so, it
applies to entire class.
4/30/2019 6
Example:
 public partial class myPartialClass
{
public void firstMethod()
{
// code…
}
}
public partial class myPartialClass
{
public void secondMethod()
{
// code…
}
}
4/30/2019 7
Sealed Class
 A sealed class is a class which cannot be inherited.
 A sealed class cannot be a base class.
 The modifier abstract cannot be applied to a sealed
class.
 To access the members of a sealed class, you must
create objects of that class.
 Sealed Class is denoted by the keyword sealed.
4/30/2019 8
Example:
sealed class mySealedClass
{
int a;
int b;
}
Class mainClass
{
public static void Main()
{
mySealedClass obj = new mySealedClass();
obj.a = 5;
obj.b = 7;
Console.WriteLine("a = {0}, b = {1}", obj.a,
obj.b);
}
}
4/30/2019 9
Static Class
A Static Class is one which cannot be instantiated. The keyword new cannot be
used with static classes as members of such class can be called directly by using
the class name itself.
It is a form of information hiding. You can use regular classes and
static classes in the same way, but the static modifier imposes an extra
restriction. The constructor is eliminated.
Static classes are loaded automatically by the .NET Framework
CLR when that program or namespace containing the class is
loaded.
Following are the main characteristics of a static class:-
•A Static Class can only have static members.
•A Static Class cannot be instantiated.
•A Static Class is sealed, so cannot be inherited.
•A Static Class cannot have a constructor (except static constructor).
Static Class is denoted by the keyword static.
4/30/2019 10
Example
 public static class Settings
{ static int i;
public static string GetName()
{ return "MyName"; }
}
class Program { static void Main(string[] args)
{ string str=Settings.GetName();
Console.Write(str);
Console.Read();
} }
4/30/2019 11
Nested Class
 Nested classes are classes within classes.
Eg--
class OurOuterClass
{
public static void Main()
{
System.Console.WriteLine("OurOuterClass");
}
class OurNestedClass { }
}
4/30/2019 12
Thank You
4/30/2019 13

More Related Content

What's hot (20)

PPTX
This keyword in java
Hitesh Kumar
 
PDF
Arrays in Java
Naz Abdalla
 
PPTX
C# classes objects
Dr.Neeraj Kumar Pandey
 
PPT
Methods in C#
Prasanna Kumar SM
 
PPT
Method overriding
Azaz Maverick
 
PPTX
Java abstract class & abstract methods
Shubham Dwivedi
 
PPTX
Constructor in java
Hitesh Kumar
 
PPT
C# basics
Dinesh kumar
 
PPTX
Javascript validating form
Jesus Obenita Jr.
 
PDF
Java I/o streams
Hamid Ghorbani
 
PPSX
Elements of Java Language
Hitesh-Java
 
PDF
Java Basic Oops Concept
atozknowledge .com
 
PPTX
Collections and its types in C# (with examples)
Aijaz Ali Abro
 
PPT
Java interfaces
Raja Sekhar
 
PPT
Java: Inheritance
Tareq Hasan
 
PPTX
Classes, objects in JAVA
Abhilash Nair
 
PDF
Java Presentation For Syntax
PravinYalameli
 
PDF
Object-oriented Programming-with C#
Doncho Minkov
 
PPTX
Inheritance in java
RahulAnanda1
 
PDF
Class and Objects in Java
Spotle.ai
 
This keyword in java
Hitesh Kumar
 
Arrays in Java
Naz Abdalla
 
C# classes objects
Dr.Neeraj Kumar Pandey
 
Methods in C#
Prasanna Kumar SM
 
Method overriding
Azaz Maverick
 
Java abstract class & abstract methods
Shubham Dwivedi
 
Constructor in java
Hitesh Kumar
 
C# basics
Dinesh kumar
 
Javascript validating form
Jesus Obenita Jr.
 
Java I/o streams
Hamid Ghorbani
 
Elements of Java Language
Hitesh-Java
 
Java Basic Oops Concept
atozknowledge .com
 
Collections and its types in C# (with examples)
Aijaz Ali Abro
 
Java interfaces
Raja Sekhar
 
Java: Inheritance
Tareq Hasan
 
Classes, objects in JAVA
Abhilash Nair
 
Java Presentation For Syntax
PravinYalameli
 
Object-oriented Programming-with C#
Doncho Minkov
 
Inheritance in java
RahulAnanda1
 
Class and Objects in Java
Spotle.ai
 

Similar to C# Types of classes (20)

PPTX
OOPs & C++ UNIT 3
Dr. SURBHI SAROHA
 
PDF
Classes, objects, methods, constructors, this keyword in java
TharuniDiddekunta
 
PPTX
Inner Classes & Multi Threading in JAVA
Tech_MX
 
PPTX
type of class in c#
tahria123
 
PPTX
Object Oriented Programming with C#
foreverredpb
 
PPTX
Class and object
prabhat kumar
 
PPT
inheritance
Amir_Mukhtar
 
PDF
C++ Notes
MOHAMED RIYAZUDEEN
 
PPTX
class c++
vinay chauhan
 
PPT
4 Classes & Objects
Praveen M Jigajinni
 
PPT
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
Venugopalavarma Raja
 
PPTX
702641313-CS3391-OBJORIENTEDPS-Unit-2.pptx
SAJITHABANUS
 
DOCX
JAVA Notes - All major concepts covered with examples
Sunil Kumar Gunasekaran
 
PDF
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
Akhil Mittal
 
PPT
Inheritance, polymorphisam, abstract classes and composition)
farhan amjad
 
PDF
Inheritance
Pranali Chaudhari
 
PPT
9781439035665 ppt ch10
Terry Yoast
 
PDF
Class and object in C++ By Pawan Thakur
Govt. P.G. College Dharamshala
 
DOCX
Class notes(week 6) on inheritance and multiple inheritance
Kuntal Bhowmick
 
PPT
11 Inheritance.ppt
LadallaRajKumar
 
OOPs & C++ UNIT 3
Dr. SURBHI SAROHA
 
Classes, objects, methods, constructors, this keyword in java
TharuniDiddekunta
 
Inner Classes & Multi Threading in JAVA
Tech_MX
 
type of class in c#
tahria123
 
Object Oriented Programming with C#
foreverredpb
 
Class and object
prabhat kumar
 
inheritance
Amir_Mukhtar
 
class c++
vinay chauhan
 
4 Classes & Objects
Praveen M Jigajinni
 
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
Venugopalavarma Raja
 
702641313-CS3391-OBJORIENTEDPS-Unit-2.pptx
SAJITHABANUS
 
JAVA Notes - All major concepts covered with examples
Sunil Kumar Gunasekaran
 
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
Akhil Mittal
 
Inheritance, polymorphisam, abstract classes and composition)
farhan amjad
 
Inheritance
Pranali Chaudhari
 
9781439035665 ppt ch10
Terry Yoast
 
Class and object in C++ By Pawan Thakur
Govt. P.G. College Dharamshala
 
Class notes(week 6) on inheritance and multiple inheritance
Kuntal Bhowmick
 
11 Inheritance.ppt
LadallaRajKumar
 
Ad

More from Prem Kumar Badri (20)

PPTX
Module 15 attributes
Prem Kumar Badri
 
PPTX
Module 14 properties and indexers
Prem Kumar Badri
 
PPTX
Module 12 aggregation, namespaces, and advanced scope
Prem Kumar Badri
 
PPTX
Module 13 operators, delegates, and events
Prem Kumar Badri
 
PPTX
Module 11 : Inheritance
Prem Kumar Badri
 
PPTX
Module 10 : creating and destroying objects
Prem Kumar Badri
 
PPTX
Module 9 : using reference type variables
Prem Kumar Badri
 
PPTX
Module 8 : Implementing collections and generics
Prem Kumar Badri
 
PPTX
Module 7 : Arrays
Prem Kumar Badri
 
PPTX
Module 6 : Essentials of Object Oriented Programming
Prem Kumar Badri
 
PPTX
Module 5 : Statements & Exceptions
Prem Kumar Badri
 
PPTX
Module 4 : methods & parameters
Prem Kumar Badri
 
PPTX
Module 3 : using value type variables
Prem Kumar Badri
 
PPTX
Module 2: Overview of c#
Prem Kumar Badri
 
PPTX
Module 1 : Overview of the Microsoft .NET Platform
Prem Kumar Badri
 
PPTX
C# Non generics collection
Prem Kumar Badri
 
PPTX
C# Multi threading
Prem Kumar Badri
 
PPT
C# Method overloading
Prem Kumar Badri
 
PPTX
C# Inheritance
Prem Kumar Badri
 
PPTX
C# Generic collections
Prem Kumar Badri
 
Module 15 attributes
Prem Kumar Badri
 
Module 14 properties and indexers
Prem Kumar Badri
 
Module 12 aggregation, namespaces, and advanced scope
Prem Kumar Badri
 
Module 13 operators, delegates, and events
Prem Kumar Badri
 
Module 11 : Inheritance
Prem Kumar Badri
 
Module 10 : creating and destroying objects
Prem Kumar Badri
 
Module 9 : using reference type variables
Prem Kumar Badri
 
Module 8 : Implementing collections and generics
Prem Kumar Badri
 
Module 7 : Arrays
Prem Kumar Badri
 
Module 6 : Essentials of Object Oriented Programming
Prem Kumar Badri
 
Module 5 : Statements & Exceptions
Prem Kumar Badri
 
Module 4 : methods & parameters
Prem Kumar Badri
 
Module 3 : using value type variables
Prem Kumar Badri
 
Module 2: Overview of c#
Prem Kumar Badri
 
Module 1 : Overview of the Microsoft .NET Platform
Prem Kumar Badri
 
C# Non generics collection
Prem Kumar Badri
 
C# Multi threading
Prem Kumar Badri
 
C# Method overloading
Prem Kumar Badri
 
C# Inheritance
Prem Kumar Badri
 
C# Generic collections
Prem Kumar Badri
 
Ad

Recently uploaded (20)

PPTX
Gupta Art & Architecture Temple and Sculptures.pptx
Virag Sontakke
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PPTX
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
PPTX
Electrophysiology_of_Heart. Electrophysiology studies in Cardiovascular syste...
Rajshri Ghogare
 
PPTX
Introduction to Probability(basic) .pptx
purohitanuj034
 
PDF
Exploring-the-Investigative-World-of-Science.pdf/8th class curiosity/1st chap...
Sandeep Swamy
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
PPTX
Digital Professionalism and Interpersonal Competence
rutvikgediya1
 
PPT
DRUGS USED IN THERAPY OF SHOCK, Shock Therapy, Treatment or management of shock
Rajshri Ghogare
 
PPTX
Constitutional Design Civics Class 9.pptx
bikesh692
 
PPTX
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
PDF
Tips for Writing the Research Title with Examples
Thelma Villaflores
 
PDF
Stepwise procedure (Manually Submitted & Un Attended) Medical Devices Cases
MUHAMMAD SOHAIL
 
PDF
John Keats introduction and list of his important works
vatsalacpr
 
PPTX
Unlock the Power of Cursor AI: MuleSoft Integrations
Veera Pallapu
 
PPTX
Cybersecurity: How to Protect your Digital World from Hackers
vaidikpanda4
 
PPTX
Top 10 AI Tools, Like ChatGPT. You Must Learn In 2025
Digilearnings
 
DOCX
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
Rules and Regulations of Madhya Pradesh Library Part-I
SantoshKumarKori2
 
Gupta Art & Architecture Temple and Sculptures.pptx
Virag Sontakke
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
Electrophysiology_of_Heart. Electrophysiology studies in Cardiovascular syste...
Rajshri Ghogare
 
Introduction to Probability(basic) .pptx
purohitanuj034
 
Exploring-the-Investigative-World-of-Science.pdf/8th class curiosity/1st chap...
Sandeep Swamy
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
Digital Professionalism and Interpersonal Competence
rutvikgediya1
 
DRUGS USED IN THERAPY OF SHOCK, Shock Therapy, Treatment or management of shock
Rajshri Ghogare
 
Constitutional Design Civics Class 9.pptx
bikesh692
 
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
Tips for Writing the Research Title with Examples
Thelma Villaflores
 
Stepwise procedure (Manually Submitted & Un Attended) Medical Devices Cases
MUHAMMAD SOHAIL
 
John Keats introduction and list of his important works
vatsalacpr
 
Unlock the Power of Cursor AI: MuleSoft Integrations
Veera Pallapu
 
Cybersecurity: How to Protect your Digital World from Hackers
vaidikpanda4
 
Top 10 AI Tools, Like ChatGPT. You Must Learn In 2025
Digilearnings
 
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
Rules and Regulations of Madhya Pradesh Library Part-I
SantoshKumarKori2
 

C# Types of classes

  • 2. Definition:  A class is a construct that enables you to create your own custom types by grouping together variables of other types, methods and events.  A class is like a blueprint. It defines the data and behavior of a type.  When you define a class, you define a blueprint for a data type. This doesn't actually define any data, but it does define what the class name means, that is, what an object of the class will consist of and what operations can be performed on such an object. Objects are instances of a class. The methods and variables that constitute a class are called members of the class. Declaration : Classes are declared by using the class keyword, as shown in the following example: <access_specifier> class <class_name> { //Fields, properties, methods and events go here... } 4/30/2019 2
  • 3. Types of Classes  Concrete Class  Abstract Class  Partial Class  Sealed Class  Static Class  Nested Class 4/30/2019 3
  • 4. Abstract Class  An Abstract Class means that, no object of this class can be instantiated, but can make derivation of this. It can serve the purpose of base class only as no object of this class can be created. Abstract Class is denoted by the keyword abstract.  Use abstract when all sub-classes have to implement the method/property.  Declaration of abstract class is :: abstract class absClass { }  An abstract class can contain either abstract methods or non abstract methods. Abstract members do not have any implementation in the abstract class, but the same has to be provided in its derived class. Eg. of abstract methord — abstract class absClass { public abstract void abstractMethod(); }  Eg. of abstract class only with non abstract members. abstract class absClass { public void NonAbstractMethod() { Console.WriteLine("NonAbstract Method"); } }  An abstract class can be derived from another abstract class. In that case, in the derived class, it is optional to implement the abstract method(s) of the base class. 4/30/2019 4
  • 5. Example: // Base abstract class abstract class baseClass { public abstract int addNumbers (int a, int b); public abstract int multiplyNumbers(int a, int b); } // Derived abstract class abstract class derivedClass:baseClass { // implementing addNumbers… public override int addnumbers (int a, int b) { return a+b; } } // Derived class from 2nd class (derivedClass) class anyClass: derivedClass { // implementing multiplyNumbers of baseClass… public override int multiplyNumbers(int a, int b) { return a*b; } } In the above example, we only implemented addNumbers in the derived abstract class (derivedClass). The abstract method multiplyNumbers is implemented in the anyClass, which is in turn derived from derivedClass. 4/30/2019 5
  • 6. Partial Class  This special type of class introduced with .Net Framework 2.0  Partial Class allows its members – method, properties, and events – to be divided into multiple source files.  At compile time these files get combined into a single class.  Partial Class is denoted by the keyword partial. Do's and don'ts about partial class:- • All the parts of a partial class must be prefixed with the keyword partial. • Accessibility, signature etc. must be same in all parts of the partial class. • You cannot seal one part of the partial class. In that case entire class in sealed. • If you define any part of the partial class abstract, entire class will become abstract. • Inheritance cannot be applied to a part of partial class. If you do so, it applies to entire class. 4/30/2019 6
  • 7. Example:  public partial class myPartialClass { public void firstMethod() { // code… } } public partial class myPartialClass { public void secondMethod() { // code… } } 4/30/2019 7
  • 8. Sealed Class  A sealed class is a class which cannot be inherited.  A sealed class cannot be a base class.  The modifier abstract cannot be applied to a sealed class.  To access the members of a sealed class, you must create objects of that class.  Sealed Class is denoted by the keyword sealed. 4/30/2019 8
  • 9. Example: sealed class mySealedClass { int a; int b; } Class mainClass { public static void Main() { mySealedClass obj = new mySealedClass(); obj.a = 5; obj.b = 7; Console.WriteLine("a = {0}, b = {1}", obj.a, obj.b); } } 4/30/2019 9
  • 10. Static Class A Static Class is one which cannot be instantiated. The keyword new cannot be used with static classes as members of such class can be called directly by using the class name itself. It is a form of information hiding. You can use regular classes and static classes in the same way, but the static modifier imposes an extra restriction. The constructor is eliminated. Static classes are loaded automatically by the .NET Framework CLR when that program or namespace containing the class is loaded. Following are the main characteristics of a static class:- •A Static Class can only have static members. •A Static Class cannot be instantiated. •A Static Class is sealed, so cannot be inherited. •A Static Class cannot have a constructor (except static constructor). Static Class is denoted by the keyword static. 4/30/2019 10
  • 11. Example  public static class Settings { static int i; public static string GetName() { return "MyName"; } } class Program { static void Main(string[] args) { string str=Settings.GetName(); Console.Write(str); Console.Read(); } } 4/30/2019 11
  • 12. Nested Class  Nested classes are classes within classes. Eg-- class OurOuterClass { public static void Main() { System.Console.WriteLine("OurOuterClass"); } class OurNestedClass { } } 4/30/2019 12