SlideShare a Scribd company logo
1 of 16
Understanding
Class, Object & Interface
Md. Shohag Mia
Software Developer (C#)
shohag-ds@outlook.com
Contents
 Introductions
 Definition of Class, Object & Interface
 Adding variable & methods into Class
 Class member access modifiers & Constructor
 Creating objects & accessing class member
 Static Member for class
 Creating & Implement interface into class
 Distinguish between Class, Object & Interface
 Questions
Introduction
Class & Object are the basic concepts of Object Oriented Programming which revolve
around the real-life entities.
In C#, classes support the polymorphism, inheritance and also provide the concept of
derived classes and base classes.
Interfaces in Object Oriented Programming Languages, An interface is a
programming structure/syntax that allows the computer to enforce certain properties
on an object (class).
Definition of Class
Class:
A class is like a blueprint of specific object. A class enables you to create your own
custom types by grouping together variables of other types, properties, behavior,
methods and events etc. Define an interface by using the class keyword.
Example- Every object has some color, shape and functionalities etc.
Syntax:
public class MyClass
{
//Here are Properties, Methods & Events
}
Definition of Object
Object:
An object is basically a block of memory that has been allocated and configured according
to the blueprint of the class. A program may create many objects of the same class.
Objects are also called instances and they can be stored in either a named variable or in an
array or collection. Define an interface by using the new keyword.
Example:
Customer, Student, Mobile Phone & Car etc.
Syntax:
BankAccount account = new BankAccount()
Definition of Interface
Interface:
An interface is like an abstract base class. Any class or struct that implements the interface must
implement all its members. An interface can't be instantiated directly. Its members are implemented by
any class or struct that implements the interface. Interfaces can contain events, indexers, methods,
and properties. Define an interface by using the interface keyword.
Interfaces in C# are a means to get around the lack of multiple inheritance in C#, meaning you can’t
inherit from multiple classes but you can implement multiple interfaces.
Example: All bank account holders can be operate cash withdrawal & deposit commonly.
Syntax:
interface IMyInterface
{
// contain events, indexers, methods, and properties here…
}
Adding variable/Properties & methods into
Class
Class member access modifiers
Creating objects & accessing class member
Static Member for a class
“static” means “relating to the type itself, rather than an instance of the type”. You access a static member using the
type name instead of a reference or a value, e.g. DateTime.Now()
In addition to methods and variables, you can also declare a class to be static (since C# 2.0). A static class cannot be
instantiated and can only contain static members.
Creating & Implement interface into class
Distinguish between Class, Object & Interface
Class Object Interface
A class describes the attributes and
behaviors (Blueprint) of an object.
An object is the instance of the class to
use variables and methods from inside the
class.
An interface contains behaviors that a
derived class implements it.
A class may contain abstract methods,
concrete methods & constructor.
A class may contain variables and
methods.
An interface contains only abstract methods
& Doesn’t contains constructor.
Members of a class can be public, private,
protected or default.
Internal is the default if no access
modifier is specified.
All the members of the interface are public
by default.
Classes have logical existence. Objects have a physical existence.
Interface have logical existence.
A class doesn't take any memory spaces
when a programmer creates one.
An object takes memory when a
programmer creates one.
A interface doesn't take any memory
spaces but only for carry on reference.
The class has to be declared only once. Objects can be declared several times
depending on the requirement.
The interface has to be declared only
once.
Demo with Class
Demo with Interface
Try to Resolve
 What is class?
 What is object?
 What is interface?
 Difference between Class & Object?
 Difference between Class & Interface?
 Why we use static keyword?
 How static member is accessed?
 What is the benefits of interface?
 Can you explain about constructor & deconstructor?
 Can you create an instance of an interface?
 Can you create an instance of an abstract class?
 Why we can’t create an object of an abstract class?
 Why we can’t specify the accessibility modifier for methods inside the interface?
 Is it possible can have multiple methods in a single class?
 Is it necessary for abstract class to have abstract method?
 When do you favor abstract class over interface?
Any questions?

More Related Content

What's hot

Jedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented conceptsJedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented concepts
Maryo Manjaruni
 
Object-Oriented Concepts
Object-Oriented ConceptsObject-Oriented Concepts
Object-Oriented Concepts
Abdalla Mahmoud
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++
Swarup Kumar Boro
 

What's hot (20)

Friend function in c++
Friend function in c++ Friend function in c++
Friend function in c++
 
Total oop in c# dot net
Total oop in c# dot netTotal oop in c# dot net
Total oop in c# dot net
 
Core java Training in Chennai
Core java Training in ChennaiCore java Training in Chennai
Core java Training in Chennai
 
Object oriented programming interview questions
Object oriented programming interview questionsObject oriented programming interview questions
Object oriented programming interview questions
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
 
Jedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented conceptsJedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented concepts
 
Object Orinted Programing(OOP) concepts \
Object Orinted Programing(OOP) concepts \Object Orinted Programing(OOP) concepts \
Object Orinted Programing(OOP) concepts \
 
Object-Oriented Concepts
Object-Oriented ConceptsObject-Oriented Concepts
Object-Oriented Concepts
 
C#, OOP introduction and examples
C#, OOP introduction and examplesC#, OOP introduction and examples
C#, OOP introduction and examples
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Inheritance in oops
Inheritance in oopsInheritance in oops
Inheritance in oops
 
Abstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAbstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and Interfaces
 
Abstract class and Interface
Abstract class and InterfaceAbstract class and Interface
Abstract class and Interface
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++
 
Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple Inheritance
 
Object Oriented Programming using C++ Part II
Object Oriented Programming using C++ Part IIObject Oriented Programming using C++ Part II
Object Oriented Programming using C++ Part II
 
Object Oriented Concepts in Real Projects
Object Oriented Concepts in Real ProjectsObject Oriented Concepts in Real Projects
Object Oriented Concepts in Real Projects
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles
 

Similar to Understanding class, object & interface

Object-oriented programming 3.pptx
Object-oriented programming 3.pptxObject-oriented programming 3.pptx
Object-oriented programming 3.pptx
Adikhan27
 
oops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdfoops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdf
ArpitaJana28
 

Similar to Understanding class, object & interface (20)

Learn C# Programming - Classes & Inheritance
Learn C# Programming - Classes & InheritanceLearn C# Programming - Classes & Inheritance
Learn C# Programming - Classes & Inheritance
 
C#.net interview questions for dynamics 365 ce crm developers
C#.net interview questions for dynamics 365 ce crm developersC#.net interview questions for dynamics 365 ce crm developers
C#.net interview questions for dynamics 365 ce crm developers
 
Object-oriented programming 3.pptx
Object-oriented programming 3.pptxObject-oriented programming 3.pptx
Object-oriented programming 3.pptx
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
 
Class properties
Class propertiesClass properties
Class properties
 
C# concepts
C# conceptsC# concepts
C# concepts
 
Unusual C# - OOP
Unusual C# - OOPUnusual C# - OOP
Unusual C# - OOP
 
OOP interview questions & answers.
OOP interview questions & answers.OOP interview questions & answers.
OOP interview questions & answers.
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 
Mit4021–%20 c# and .net
Mit4021–%20 c# and .netMit4021–%20 c# and .net
Mit4021–%20 c# and .net
 
C# program structure
C# program structureC# program structure
C# program structure
 
Oops
OopsOops
Oops
 
Polymorphism and interface in vb.net
Polymorphism and interface in vb.netPolymorphism and interface in vb.net
Polymorphism and interface in vb.net
 
Objects and Types C#
Objects and Types C#Objects and Types C#
Objects and Types C#
 
oops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdfoops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdf
 
C# interview
C# interviewC# interview
C# interview
 
Interfaces & Packages V2
Interfaces & Packages V2Interfaces & Packages V2
Interfaces & Packages V2
 
C# interview-questions
C# interview-questionsC# interview-questions
C# interview-questions
 
Introduction of C# & MVC
Introduction of C# & MVCIntroduction of C# & MVC
Introduction of C# & MVC
 
Sda 7
Sda   7Sda   7
Sda 7
 

Recently uploaded

Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Recently uploaded (20)

WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
 
WSO2CON 2024 - Software Engineering for Digital Businesses
WSO2CON 2024 - Software Engineering for Digital BusinessesWSO2CON 2024 - Software Engineering for Digital Businesses
WSO2CON 2024 - Software Engineering for Digital Businesses
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AI
 
WSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration ToolingWSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration Tooling
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdfAzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
 
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
 

Understanding class, object & interface

  • 1. Understanding Class, Object & Interface Md. Shohag Mia Software Developer (C#) shohag-ds@outlook.com
  • 2. Contents  Introductions  Definition of Class, Object & Interface  Adding variable & methods into Class  Class member access modifiers & Constructor  Creating objects & accessing class member  Static Member for class  Creating & Implement interface into class  Distinguish between Class, Object & Interface  Questions
  • 3. Introduction Class & Object are the basic concepts of Object Oriented Programming which revolve around the real-life entities. In C#, classes support the polymorphism, inheritance and also provide the concept of derived classes and base classes. Interfaces in Object Oriented Programming Languages, An interface is a programming structure/syntax that allows the computer to enforce certain properties on an object (class).
  • 4. Definition of Class Class: A class is like a blueprint of specific object. A class enables you to create your own custom types by grouping together variables of other types, properties, behavior, methods and events etc. Define an interface by using the class keyword. Example- Every object has some color, shape and functionalities etc. Syntax: public class MyClass { //Here are Properties, Methods & Events }
  • 5. Definition of Object Object: An object is basically a block of memory that has been allocated and configured according to the blueprint of the class. A program may create many objects of the same class. Objects are also called instances and they can be stored in either a named variable or in an array or collection. Define an interface by using the new keyword. Example: Customer, Student, Mobile Phone & Car etc. Syntax: BankAccount account = new BankAccount()
  • 6. Definition of Interface Interface: An interface is like an abstract base class. Any class or struct that implements the interface must implement all its members. An interface can't be instantiated directly. Its members are implemented by any class or struct that implements the interface. Interfaces can contain events, indexers, methods, and properties. Define an interface by using the interface keyword. Interfaces in C# are a means to get around the lack of multiple inheritance in C#, meaning you can’t inherit from multiple classes but you can implement multiple interfaces. Example: All bank account holders can be operate cash withdrawal & deposit commonly. Syntax: interface IMyInterface { // contain events, indexers, methods, and properties here… }
  • 7. Adding variable/Properties & methods into Class
  • 9. Creating objects & accessing class member
  • 10. Static Member for a class “static” means “relating to the type itself, rather than an instance of the type”. You access a static member using the type name instead of a reference or a value, e.g. DateTime.Now() In addition to methods and variables, you can also declare a class to be static (since C# 2.0). A static class cannot be instantiated and can only contain static members.
  • 11. Creating & Implement interface into class
  • 12. Distinguish between Class, Object & Interface Class Object Interface A class describes the attributes and behaviors (Blueprint) of an object. An object is the instance of the class to use variables and methods from inside the class. An interface contains behaviors that a derived class implements it. A class may contain abstract methods, concrete methods & constructor. A class may contain variables and methods. An interface contains only abstract methods & Doesn’t contains constructor. Members of a class can be public, private, protected or default. Internal is the default if no access modifier is specified. All the members of the interface are public by default. Classes have logical existence. Objects have a physical existence. Interface have logical existence. A class doesn't take any memory spaces when a programmer creates one. An object takes memory when a programmer creates one. A interface doesn't take any memory spaces but only for carry on reference. The class has to be declared only once. Objects can be declared several times depending on the requirement. The interface has to be declared only once.
  • 15. Try to Resolve  What is class?  What is object?  What is interface?  Difference between Class & Object?  Difference between Class & Interface?  Why we use static keyword?  How static member is accessed?  What is the benefits of interface?  Can you explain about constructor & deconstructor?  Can you create an instance of an interface?  Can you create an instance of an abstract class?  Why we can’t create an object of an abstract class?  Why we can’t specify the accessibility modifier for methods inside the interface?  Is it possible can have multiple methods in a single class?  Is it necessary for abstract class to have abstract method?  When do you favor abstract class over interface?