SlideShare a Scribd company logo
1 of 24
About Abstract Class
• Abstract class in csharp is defined using "abstract"
keyword
• An abstract class may contain abstract methods and
accesses (properties).
• Non abstract methods or properties should provide
actual implementation in an abstract class.
• Abstract classes that cannot be instantiated mean we
cannot able to create an object of an abstract class but
abstract class can be implemented to child classes like
a common base class. An abstract class can be partially
implemented or not at all implemented.
Syntax
1
2
3

abstract class absCalculator
...code starts here
}
Abstract Method
In an abstract class a method which has a
keyword "abstract" and doesn't provide any
implementation is called abstract method.The
implementation logic of abstract methods is
provided by the child classes or derived
classes.Child classes use keyword "override"
with same method name (as abstract method
name) to provide further implementation of
abstract methods.
Non Abstract Method
In an abstract class a method which doesn't
have a keyword "abstract" and provide any
implementation is called non abstract method.
Why Abstract Class
Abstract class enforces derived classes to
provide all implementation logic for abstract
methods or properties.
create an abstract class "absCalculate" having
abstract methods and non abstract methods.
01
02
03
04
05
06
07
08
09
10
11

abstract class absCalculate

//A Non abstract method
public int Addition(int Num1, int Num2)
return Num1 + Num2;
}
//An abstract method, to be overridden in derived class
public abstract int Multiplication(int Num1, int Num2);
}
create a class "clsCalculate" and
implement it with abstract class
"absCalculate".
1
2
3
4

class clsCalculate:absCalculate

...code
}
Now lets give implementation for an abstract
method using override keyword implementing
the abstract method
1
class clsCalculate:absCalculate
2
3
4
//using override keyword implementing the
abstract method
5
public override int Multiplication(int Num1, int
Num2)
6
7
return Num1 * Num2;
8
}
9
}
create an object of class "clsCalculate" in our
main program of an console application
01
class Program
02
03
04
static void Main(string[] args)
05
06
07
Console.WriteLine("Please Enter First Number");
08
int num1 = Convert.ToInt16(Console.ReadLine());
09
10
Console.WriteLine("Please Enter Second Number");
11
int num2 = Convert.ToInt16(Console.ReadLine());
12
13
absCalculate objabCal = new clsCalculate();
14
int add = objabCal.Addition(num1, num2);
15
int multiplied = objabCal.Multiplication(num1, num2);
16
Console.WriteLine("Added Number is : 0}, Multiplied Number is :
1}", add, multiplied);
17
}
18
}
Output
What is an Interface?
• An interface looks like a class but has got no implementation. In an
interface we cannot do any implementation but we can declare
signatures of properties, methods, delegates and events.
• Implementation part is been handle by the class that implements
the interface. Implemented interface enforces the class like a
standard contract to provide all implementation of interface
members.
• We can implement single interface or multiple interfaces to the
class. By default interfaces are public.

• We declare interface by using "interface" keyword.
interface "IEmployee" with signature
of a method
"DisplayEmployeeDetails".
•
•
•
•
•

1 interface IEmployee{
2
3 void DisplayEmployeeDetails();
4
5 }
Various Forms of implementing
interface
There are two of ways of implementing
interfaces
• Explicit
• Implicit
Explicit interface implementation
• When we have two different interfaces with
same method name then in that scenario we
can use explicit interface implementation.
• To implement an interface explicitly we have
to define an interface name followed by (".")
dot operator then the method name
we have two different interfaces "IEmployee"
and "ICompany" with same method name.
1
2
3
4
5
6
7

public interface IEmployee{
void DisplayEmployeeDetails();
}
public interface ICompany{
void DisplayEmployeeDetails();
}
In order to implement an interface explicitly we
have to define the interface name followed by
(".") dot operator before method name
1
public class Employee : IEmployee,ICompany
2
{
3
void ICompany.DisplayEmployeeDetails(){
4
Console.WriteLine("ICompany Employee
Name --> Questpond and Employee Code --> 009");
5
}
6
void IEmployee.DisplayEmployeeDetails(){
7
Console.WriteLine("IEmployee Employee
Name --> Questpond and Employee Code --> 009");
8
}
9
}
create the objects of two interfaces "IEmployee"
and "ICompany" in our main method of a
Console Application program.
01
02
03
04
05
06
07
08
09
10
11
12

class Program{
static void Main(string[] args)
{
IEmployee IEmp = new clsEmployee();
IEmp.DisplayEmployeeDetails();
ICompany IComp = new clsEmployee();
IComp.DisplayEmployeeDetails();
}
}
Output
Implicit interface implementation
demonstration of an interface
"IEmployee" with signature of a
method "DisplayEmployeeDetails".
1
2
3
4

interface IEmployee
{
void DisplayEmployeeDetails();
}
create a class "Employee" and
implement the interface implicitly
1
public class Employee : IEmployee
2
{
3
public void DisplayEmployeeDetails()
4
{
5
Console.WriteLine("Employee Name
--> Questpond and Employee Code --> 009");
6
}
7
}
create the objects of an interface
"IEmployee" in our main method of a
Console Application program
1
2
3
4
5
6
7
8
9

public class Program{
static void Main(string[] args)
{
IEmployee IEmp = new clsEmployee();
IEmp.DisplayEmployeeDetails();
}
}
Output

More Related Content

What's hot (20)

Compiler lab final report writing
Compiler lab final report writingCompiler lab final report writing
Compiler lab final report writing
 
Functions
FunctionsFunctions
Functions
 
Operators In Java Part - 8
Operators In Java Part - 8Operators In Java Part - 8
Operators In Java Part - 8
 
Core java day4
Core java day4Core java day4
Core java day4
 
Reading and writting
Reading and writtingReading and writting
Reading and writting
 
Interface
InterfaceInterface
Interface
 
Operators
OperatorsOperators
Operators
 
Operators
OperatorsOperators
Operators
 
A simple program C# program
A simple program C# programA simple program C# program
A simple program C# program
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
 
Java chapter 3
Java chapter 3Java chapter 3
Java chapter 3
 
Java codes
Java codesJava codes
Java codes
 
Simple Java Programs
Simple Java ProgramsSimple Java Programs
Simple Java Programs
 
Introduction to Matlab Scripts
Introduction to Matlab ScriptsIntroduction to Matlab Scripts
Introduction to Matlab Scripts
 
Intake 38 12
Intake 38 12Intake 38 12
Intake 38 12
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
 
Js
JsJs
Js
 
Pi j1.3 operators
Pi j1.3 operatorsPi j1.3 operators
Pi j1.3 operators
 
Java small steps - 2019
Java   small steps - 2019Java   small steps - 2019
Java small steps - 2019
 
Generic Programming
Generic ProgrammingGeneric Programming
Generic Programming
 

Viewers also liked

AR+S The Role Of Abstraction In Human Computer Interaction
AR+S   The Role Of Abstraction In Human Computer InteractionAR+S   The Role Of Abstraction In Human Computer Interaction
AR+S The Role Of Abstraction In Human Computer InteractionAli Rıza SARAL
 
Final Animation Assessment Presentation: The Abstraction of Bohemian Rhapsody.
Final Animation Assessment Presentation: The Abstraction of Bohemian Rhapsody. Final Animation Assessment Presentation: The Abstraction of Bohemian Rhapsody.
Final Animation Assessment Presentation: The Abstraction of Bohemian Rhapsody. Sarah Ju-En Tan
 
IoT and META-engineering with Service Templates
IoT and META-engineering with Service TemplatesIoT and META-engineering with Service Templates
IoT and META-engineering with Service TemplatesHans A. Kielland Aanesen
 
Java topology abstraction service for ip-vp ns
Java  topology abstraction service for ip-vp nsJava  topology abstraction service for ip-vp ns
Java topology abstraction service for ip-vp nsecwayerode
 
06 abstract-classes
06 abstract-classes06 abstract-classes
06 abstract-classesAnup Burange
 
Object Oriented Programing JAVA presentaion
Object Oriented Programing JAVA presentaionObject Oriented Programing JAVA presentaion
Object Oriented Programing JAVA presentaionPritom Chaki
 
Character stream classes .52
Character stream classes .52Character stream classes .52
Character stream classes .52myrajendra
 
Inner classes ,annoumous and outer classes in java
Inner classes ,annoumous and outer classes in javaInner classes ,annoumous and outer classes in java
Inner classes ,annoumous and outer classes in javaAdil Mehmoood
 
Encapsulation anonymous class
Encapsulation anonymous classEncapsulation anonymous class
Encapsulation anonymous classHarry Potter
 

Viewers also liked (20)

AR+S The Role Of Abstraction In Human Computer Interaction
AR+S   The Role Of Abstraction In Human Computer InteractionAR+S   The Role Of Abstraction In Human Computer Interaction
AR+S The Role Of Abstraction In Human Computer Interaction
 
Final Animation Assessment Presentation: The Abstraction of Bohemian Rhapsody.
Final Animation Assessment Presentation: The Abstraction of Bohemian Rhapsody. Final Animation Assessment Presentation: The Abstraction of Bohemian Rhapsody.
Final Animation Assessment Presentation: The Abstraction of Bohemian Rhapsody.
 
File class.48
File class.48File class.48
File class.48
 
IoT and META-engineering with Service Templates
IoT and META-engineering with Service TemplatesIoT and META-engineering with Service Templates
IoT and META-engineering with Service Templates
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
IEEE DEST CEE 2013 - Paper 4 (1) (1)
IEEE DEST CEE 2013 - Paper 4 (1) (1)IEEE DEST CEE 2013 - Paper 4 (1) (1)
IEEE DEST CEE 2013 - Paper 4 (1) (1)
 
Core java questions
Core java questionsCore java questions
Core java questions
 
Java topology abstraction service for ip-vp ns
Java  topology abstraction service for ip-vp nsJava  topology abstraction service for ip-vp ns
Java topology abstraction service for ip-vp ns
 
Java JDBC
Java JDBCJava JDBC
Java JDBC
 
Java stereams
Java stereamsJava stereams
Java stereams
 
Java lecture
Java lectureJava lecture
Java lecture
 
06 abstract-classes
06 abstract-classes06 abstract-classes
06 abstract-classes
 
Object Oriented Programing JAVA presentaion
Object Oriented Programing JAVA presentaionObject Oriented Programing JAVA presentaion
Object Oriented Programing JAVA presentaion
 
Character stream classes .52
Character stream classes .52Character stream classes .52
Character stream classes .52
 
Inner classes ,annoumous and outer classes in java
Inner classes ,annoumous and outer classes in javaInner classes ,annoumous and outer classes in java
Inner classes ,annoumous and outer classes in java
 
PAC
PACPAC
PAC
 
Java Inner Classes
Java Inner ClassesJava Inner Classes
Java Inner Classes
 
Encapsulation anonymous class
Encapsulation anonymous classEncapsulation anonymous class
Encapsulation anonymous class
 
Abstract class
Abstract classAbstract class
Abstract class
 
Operators in java
Operators in javaOperators in java
Operators in java
 

Similar to Interface and abstraction

classes object fgfhdfgfdgfgfgfgfdoop.pptx
classes object  fgfhdfgfdgfgfgfgfdoop.pptxclasses object  fgfhdfgfdgfgfgfgfdoop.pptx
classes object fgfhdfgfdgfgfgfgfdoop.pptxarjun431527
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1stConnex
 
Procedure to create_the_calculator_application java
Procedure to create_the_calculator_application javaProcedure to create_the_calculator_application java
Procedure to create_the_calculator_application javagthe
 
Web technologies-course 12.pptx
Web technologies-course 12.pptxWeb technologies-course 12.pptx
Web technologies-course 12.pptxStefan Oprea
 
Design patterns in java script, jquery, angularjs
Design patterns in java script, jquery, angularjsDesign patterns in java script, jquery, angularjs
Design patterns in java script, jquery, angularjsRavi Bhadauria
 
Object-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modulesObject-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modulesDurgesh Singh
 
oops with java modules i & ii.ppt
oops with java modules i & ii.pptoops with java modules i & ii.ppt
oops with java modules i & ii.pptrani marri
 
Objectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxObjectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxdunhamadell
 
Polymorphism, Abstarct Class and Interface in C#
Polymorphism, Abstarct Class and Interface in C#Polymorphism, Abstarct Class and Interface in C#
Polymorphism, Abstarct Class and Interface in C#Umar Farooq
 
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCE
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCECONSTRUCTORS IN C++ +2 COMPUTER SCIENCE
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCEVenugopalavarma Raja
 
Easymock Tutorial
Easymock TutorialEasymock Tutorial
Easymock TutorialSbin m
 
Python Classes_ Empowering Developers, Enabling Breakthroughs.pdf
Python Classes_ Empowering Developers, Enabling Breakthroughs.pdfPython Classes_ Empowering Developers, Enabling Breakthroughs.pdf
Python Classes_ Empowering Developers, Enabling Breakthroughs.pdfSudhanshiBakre1
 
Programming Primer EncapsulationVB
Programming Primer EncapsulationVBProgramming Primer EncapsulationVB
Programming Primer EncapsulationVBsunmitraeducation
 

Similar to Interface and abstraction (20)

classes object fgfhdfgfdgfgfgfgfdoop.pptx
classes object  fgfhdfgfdgfgfgfgfdoop.pptxclasses object  fgfhdfgfdgfgfgfgfdoop.pptx
classes object fgfhdfgfdgfgfgfgfdoop.pptx
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
 
C#2
C#2C#2
C#2
 
Procedure to create_the_calculator_application java
Procedure to create_the_calculator_application javaProcedure to create_the_calculator_application java
Procedure to create_the_calculator_application java
 
Web technologies-course 12.pptx
Web technologies-course 12.pptxWeb technologies-course 12.pptx
Web technologies-course 12.pptx
 
Design patterns in java script, jquery, angularjs
Design patterns in java script, jquery, angularjsDesign patterns in java script, jquery, angularjs
Design patterns in java script, jquery, angularjs
 
Java Lab Manual
Java Lab ManualJava Lab Manual
Java Lab Manual
 
Refactoring Chapter11
Refactoring Chapter11Refactoring Chapter11
Refactoring Chapter11
 
Object-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modulesObject-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modules
 
oops with java modules i & ii.ppt
oops with java modules i & ii.pptoops with java modules i & ii.ppt
oops with java modules i & ii.ppt
 
JavaProgrammingManual
JavaProgrammingManualJavaProgrammingManual
JavaProgrammingManual
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Objectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxObjectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docx
 
Polymorphism, Abstarct Class and Interface in C#
Polymorphism, Abstarct Class and Interface in C#Polymorphism, Abstarct Class and Interface in C#
Polymorphism, Abstarct Class and Interface in C#
 
C# Unit 2 notes
C# Unit 2 notesC# Unit 2 notes
C# Unit 2 notes
 
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCE
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCECONSTRUCTORS IN C++ +2 COMPUTER SCIENCE
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCE
 
Easymock Tutorial
Easymock TutorialEasymock Tutorial
Easymock Tutorial
 
Constructor
ConstructorConstructor
Constructor
 
Python Classes_ Empowering Developers, Enabling Breakthroughs.pdf
Python Classes_ Empowering Developers, Enabling Breakthroughs.pdfPython Classes_ Empowering Developers, Enabling Breakthroughs.pdf
Python Classes_ Empowering Developers, Enabling Breakthroughs.pdf
 
Programming Primer EncapsulationVB
Programming Primer EncapsulationVBProgramming Primer EncapsulationVB
Programming Primer EncapsulationVB
 

Interface and abstraction

  • 1.
  • 2. About Abstract Class • Abstract class in csharp is defined using "abstract" keyword • An abstract class may contain abstract methods and accesses (properties). • Non abstract methods or properties should provide actual implementation in an abstract class. • Abstract classes that cannot be instantiated mean we cannot able to create an object of an abstract class but abstract class can be implemented to child classes like a common base class. An abstract class can be partially implemented or not at all implemented.
  • 4. Abstract Method In an abstract class a method which has a keyword "abstract" and doesn't provide any implementation is called abstract method.The implementation logic of abstract methods is provided by the child classes or derived classes.Child classes use keyword "override" with same method name (as abstract method name) to provide further implementation of abstract methods.
  • 5. Non Abstract Method In an abstract class a method which doesn't have a keyword "abstract" and provide any implementation is called non abstract method.
  • 6. Why Abstract Class Abstract class enforces derived classes to provide all implementation logic for abstract methods or properties.
  • 7. create an abstract class "absCalculate" having abstract methods and non abstract methods. 01 02 03 04 05 06 07 08 09 10 11 abstract class absCalculate //A Non abstract method public int Addition(int Num1, int Num2) return Num1 + Num2; } //An abstract method, to be overridden in derived class public abstract int Multiplication(int Num1, int Num2); }
  • 8. create a class "clsCalculate" and implement it with abstract class "absCalculate". 1 2 3 4 class clsCalculate:absCalculate ...code }
  • 9. Now lets give implementation for an abstract method using override keyword implementing the abstract method 1 class clsCalculate:absCalculate 2 3 4 //using override keyword implementing the abstract method 5 public override int Multiplication(int Num1, int Num2) 6 7 return Num1 * Num2; 8 } 9 }
  • 10. create an object of class "clsCalculate" in our main program of an console application 01 class Program 02 03 04 static void Main(string[] args) 05 06 07 Console.WriteLine("Please Enter First Number"); 08 int num1 = Convert.ToInt16(Console.ReadLine()); 09 10 Console.WriteLine("Please Enter Second Number"); 11 int num2 = Convert.ToInt16(Console.ReadLine()); 12 13 absCalculate objabCal = new clsCalculate(); 14 int add = objabCal.Addition(num1, num2); 15 int multiplied = objabCal.Multiplication(num1, num2); 16 Console.WriteLine("Added Number is : 0}, Multiplied Number is : 1}", add, multiplied); 17 } 18 }
  • 12. What is an Interface? • An interface looks like a class but has got no implementation. In an interface we cannot do any implementation but we can declare signatures of properties, methods, delegates and events. • Implementation part is been handle by the class that implements the interface. Implemented interface enforces the class like a standard contract to provide all implementation of interface members. • We can implement single interface or multiple interfaces to the class. By default interfaces are public. • We declare interface by using "interface" keyword.
  • 13. interface "IEmployee" with signature of a method "DisplayEmployeeDetails". • • • • • 1 interface IEmployee{ 2 3 void DisplayEmployeeDetails(); 4 5 }
  • 14. Various Forms of implementing interface There are two of ways of implementing interfaces • Explicit • Implicit
  • 15. Explicit interface implementation • When we have two different interfaces with same method name then in that scenario we can use explicit interface implementation. • To implement an interface explicitly we have to define an interface name followed by (".") dot operator then the method name
  • 16. we have two different interfaces "IEmployee" and "ICompany" with same method name. 1 2 3 4 5 6 7 public interface IEmployee{ void DisplayEmployeeDetails(); } public interface ICompany{ void DisplayEmployeeDetails(); }
  • 17. In order to implement an interface explicitly we have to define the interface name followed by (".") dot operator before method name 1 public class Employee : IEmployee,ICompany 2 { 3 void ICompany.DisplayEmployeeDetails(){ 4 Console.WriteLine("ICompany Employee Name --> Questpond and Employee Code --> 009"); 5 } 6 void IEmployee.DisplayEmployeeDetails(){ 7 Console.WriteLine("IEmployee Employee Name --> Questpond and Employee Code --> 009"); 8 } 9 }
  • 18. create the objects of two interfaces "IEmployee" and "ICompany" in our main method of a Console Application program. 01 02 03 04 05 06 07 08 09 10 11 12 class Program{ static void Main(string[] args) { IEmployee IEmp = new clsEmployee(); IEmp.DisplayEmployeeDetails(); ICompany IComp = new clsEmployee(); IComp.DisplayEmployeeDetails(); } }
  • 21. demonstration of an interface "IEmployee" with signature of a method "DisplayEmployeeDetails". 1 2 3 4 interface IEmployee { void DisplayEmployeeDetails(); }
  • 22. create a class "Employee" and implement the interface implicitly 1 public class Employee : IEmployee 2 { 3 public void DisplayEmployeeDetails() 4 { 5 Console.WriteLine("Employee Name --> Questpond and Employee Code --> 009"); 6 } 7 }
  • 23. create the objects of an interface "IEmployee" in our main method of a Console Application program 1 2 3 4 5 6 7 8 9 public class Program{ static void Main(string[] args) { IEmployee IEmp = new clsEmployee(); IEmp.DisplayEmployeeDetails(); } }