SlideShare a Scribd company logo
Difference between Abstraction and Encapsulation

               Abstraction                                Encapsulation
 Abstraction solves the problem in the       Encapsulation solves the problem in the
 design level.                               implementation level.
 Abstraction is used for hiding the      Encapsulation means hiding the code
 unwanted data and giving relevant data. and data into a single unit to protect the
                                         data from outside world.
 Abstraction allows us to focus on what      Encapsulation means hiding the internal
 the object does instead of how it does it   details or mechanism of how an object
                                             does something.
 Abstraction- Outer layout, used in          Encapsulation- Inner layout, used in
 terms of design.                            terms of implementation.
 For Example:-                               For Example:- Inner Implementation
  Outer Look of a Mobile Phone, like it      detail of a Mobile Phone, how keypad
 has a display screen and keypad buttons     button and Display Screen are
 to dial a number.
                                             connected with each other using circuits


Difference between Composition and Aggregation

               Composition                                 Aggregation
 Defines a strong-coupled relationship       Defines a weak-coupled relationship
 between two entities, where the one         between two entities, where one entity
 entity is part of another, and both need    could be part of another, but either can
 each other for their existence.             exist without the other, independantly.

 e.g. Human body and the Heart.              e.g.School and teacher.

 Composition implies real ownership of       Aggregation does not necessarily own
 its components                              any of its aggregates.
 Composition has a stronger bond of its      Aggregation has weaker or looser bonds
 components.                                 with its aggregates.
 Composition has components that exist       Aggregation has aggregates that live at
 at the inner level.                         the outer level.
Difference between Private Class and Sealed Class

               Private Class                               Sealed Class
 A Private class can only be accessed by A Sealed class can be accessed by any
 the class it is defined and contain within class.Private Constructor of a Private
 - it is completely inaccessible to outside Class = Sealed Class.
 classes.
 In private Class,we can create a            In Sealed class we can not create a
 constructor and therefore we can create     constructor of that class, so no instance
 an instance of that class.                  of that class is possible.
 public class A                              public sealed class A
  {                                            {
  private class B                              }
    {                                        public class B : A //ERROR
    }                                          {
  B b = new B();                               }
  }
 public class C
  {
  A.B b = new A.B(); // ERROR
  }
 The main use of Private class is to create The sealed classes are mainly used to
 a user-defined type, which we want to be prevent inheritance features of object
 accessible to that class only.             oriented programming.

 Private class(i.e private constructor) is
 also used to implement singleton
 classes(pattern). Singleton means "A
 single-instance object, and it simplify
 complex code. Singletons have a static
 property that we must access to get the
 object reference."

Difference between Static Class and Sealed Class

                Static Class                               Sealed Class
 We can neither create their instances,      We can create their instances, but cannot
 nor inherit them                            inherit them
 They can have static members only.          They can contain static as well as
                                             nonstatic members.
 ex:                                         ex:
 static class Program
{                                          sealed class demo
                                            {
 }
                                            }

                                            class abc:demo
                                            {
                                            --Wrong
                                            }
 Static classes are used when a class        The sealed classes are mainly used to
 provides functionality that is not specific prevent inheritance features of object
 to any unique instance.                     oriented programming.

Difference between Virtual method and Abstract method


      Feature                Virtual method                  Abstract method
 Overriding           Virtual method may or may        An abstract method should be
                      not override by inherited class. overriden by inherited class.

                      i.e.,Virtual method provide      i.e.,Abstract method forces
                      the derived class with the       the derived class to
                      option of overriding it.         override it.

                      Virtual = = Overridable          abstract == MustOverride
 Implementation       Virtual method has an            Abstract method does not
                      implementation.                  provide an implementation.
 Necessity to         Virtual methods allow            Abstract methods in a
 Implement            subclasses to provide their      class contain no method
                      own implementation of that       body, and are implicitly
                      method using the override        virtual
                      keyword
 Scope                Virtual methods scope to         Abstract method's scope to
                      members only.                    members and classes
 Instancing           Virtual methods - Not            Abstract method - direcly
                      applicable, as we can't          NO, but other way, Yes.
                      create instance for              We can create an instance
                      members, it is possible only     of a class that derives from
                      with classes.                    an abstract class. And we
                                                       can declare a type Abstract
                                                       class and instantiate that
                                                       as a derived class.
Example:

 public abstract class Test
 {

   public abstract void A();          // Abstract method

   public virtual void B()
   {
     Console.WriteLine("Test.B"); } // Virtual Method
   }

     public class InheritedTest : Test
     {

         public override void A()
         {
          Console.WriteLine("InheritedTest.A");
         }

         //Method B implementation is optional

         public override void B()
         {
          Console.WriteLine("InheritedTest.B");
         }
     }



Difference between Class and Static Class

                   Class                                  Static Class
 Class has Instance Members                 Static class does not have Instance
                                            Members
 In Class, Constructor has Access           In Static Class, Constructor does not
 Specifier.                                 have Access Specifier.
 In Class Constructor, initiation is done   In Static Class ,Constructor will be
 every time when an object is created       called only one time .
 for the class

 In Class, Class members can be             In Static Class, members can be
 accessed through class object.             accessed through its Class name only
Difference between Method Overloading and Method overriding in C#


         Method Overloading                        Method overriding
 Method Overloading is passing same      Method Overriding is redifining parent
 message for different functionality     class function to the child class
 Method Overloading is between the       Method Overriding is between the same
 same function name with the different   method.
 signature
 Method Overloading does not check for Method Overriding checks the return
 the return type.                      type.
 Method Overloading takes place in the   Method Overriding takes place between
 same class.                             parent and child classes
 Method Overloading is static binding    Method Overriding is a dynamic
                                         binding.

More Related Content

PPT
Developing an ASP.NET Web Application
PPT
Introduction to java beans
PPS
Java Exception handling
PPTX
Packages in java
ODP
OOP java
PPT
Object modeling
PPTX
Java swing
PPTX
10 implementing subprograms
Developing an ASP.NET Web Application
Introduction to java beans
Java Exception handling
Packages in java
OOP java
Object modeling
Java swing
10 implementing subprograms

What's hot (20)

PPT
JAVA APPLET BASICS
PPTX
Java abstract class & abstract methods
PPT
Object Oriented Programming Concepts
PPT
Android software stack
PDF
Java Basic Oops Concept
PDF
A Basic Django Introduction
PPTX
Selenium WebDriver
PPTX
OOPS In JAVA.pptx
PPTX
Web forms in ASP.net
PPTX
Fragments In Android.pptx
PPT
Introduction to Eclipse IDE
PPTX
Angular 2.0 Dependency injection
PPTX
Java Constructor
PPSX
Data Types & Variables in JAVA
PDF
API_Testing_with_Postman
PPT
Chapter 17 corba
PPTX
Multithreading
PPTX
Dependency injection presentation
PPTX
Introduction to selenium
PPT
Postman.ppt
JAVA APPLET BASICS
Java abstract class & abstract methods
Object Oriented Programming Concepts
Android software stack
Java Basic Oops Concept
A Basic Django Introduction
Selenium WebDriver
OOPS In JAVA.pptx
Web forms in ASP.net
Fragments In Android.pptx
Introduction to Eclipse IDE
Angular 2.0 Dependency injection
Java Constructor
Data Types & Variables in JAVA
API_Testing_with_Postman
Chapter 17 corba
Multithreading
Dependency injection presentation
Introduction to selenium
Postman.ppt
Ad

Similar to OOPs difference faqs-3 (20)

DOCX
Java Core Parctical
PPT
Java inheritance
PPTX
Java basics
PPTX
Oops and enums
PDF
Lecture 10
DOC
116824015 java-j2 ee
PPTX
Abstraction in java [abstract classes and Interfaces
PPTX
Unusual C# - OOP
PPTX
PPT Lecture-1.4.pptx
PPTX
Java OOPS Concept
DOCX
Core java questions
PPTX
Object Oriented Programming with C#
PDF
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
PPT
Java interfaces & abstract classes
PPT
9781439035665 ppt ch10
DOCX
Core java by amit
PPTX
Abstraction encapsulation inheritance polymorphism
DOCX
Java Core
DOC
Java interview questions
PDF
Java 06
Java Core Parctical
Java inheritance
Java basics
Oops and enums
Lecture 10
116824015 java-j2 ee
Abstraction in java [abstract classes and Interfaces
Unusual C# - OOP
PPT Lecture-1.4.pptx
Java OOPS Concept
Core java questions
Object Oriented Programming with C#
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
Java interfaces & abstract classes
9781439035665 ppt ch10
Core java by amit
Abstraction encapsulation inheritance polymorphism
Java Core
Java interview questions
Java 06
Ad

More from Umar Ali (20)

PDF
Difference between wcf and asp.net web api
PDF
Difference between ActionResult() and ViewResult()
PDF
Difference between asp.net mvc 3 and asp.net mvc 4
PDF
Difference between asp.net web api and asp.net mvc
PDF
Difference between asp.net web forms and asp.net mvc
PDF
ASP.NET MVC difference between questions list 1
ODT
Link checkers 1
PDF
Affiliate Networks Sites-1
PDF
Technical Video Training Sites- 1
PDF
US News Sites- 1
PDF
How to create user friendly file hosting link sites
PDF
Weak hadiths in tamil
PDF
Bulughul Maram in tamil
PDF
Asp.net website usage and job trends
PDF
Indian news sites- 1
PDF
Photo sharing sites- 1
PDF
File hosting search engines
PDF
Ajax difference faqs compiled- 1
PDF
ADO.NET difference faqs compiled- 1
PDF
Dotnet differences compiled -1
Difference between wcf and asp.net web api
Difference between ActionResult() and ViewResult()
Difference between asp.net mvc 3 and asp.net mvc 4
Difference between asp.net web api and asp.net mvc
Difference between asp.net web forms and asp.net mvc
ASP.NET MVC difference between questions list 1
Link checkers 1
Affiliate Networks Sites-1
Technical Video Training Sites- 1
US News Sites- 1
How to create user friendly file hosting link sites
Weak hadiths in tamil
Bulughul Maram in tamil
Asp.net website usage and job trends
Indian news sites- 1
Photo sharing sites- 1
File hosting search engines
Ajax difference faqs compiled- 1
ADO.NET difference faqs compiled- 1
Dotnet differences compiled -1

Recently uploaded (20)

PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Encapsulation_ Review paper, used for researhc scholars
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
MIND Revenue Release Quarter 2 2025 Press Release
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Understanding_Digital_Forensics_Presentation.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
Empathic Computing: Creating Shared Understanding
Mobile App Security Testing_ A Comprehensive Guide.pdf
20250228 LYD VKU AI Blended-Learning.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Big Data Technologies - Introduction.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Chapter 3 Spatial Domain Image Processing.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
sap open course for s4hana steps from ECC to s4
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Encapsulation_ Review paper, used for researhc scholars
“AI and Expert System Decision Support & Business Intelligence Systems”
MYSQL Presentation for SQL database connectivity
Building Integrated photovoltaic BIPV_UPV.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing

OOPs difference faqs-3

  • 1. Difference between Abstraction and Encapsulation Abstraction Encapsulation Abstraction solves the problem in the Encapsulation solves the problem in the design level. implementation level. Abstraction is used for hiding the Encapsulation means hiding the code unwanted data and giving relevant data. and data into a single unit to protect the data from outside world. Abstraction allows us to focus on what Encapsulation means hiding the internal the object does instead of how it does it details or mechanism of how an object does something. Abstraction- Outer layout, used in Encapsulation- Inner layout, used in terms of design. terms of implementation. For Example:- For Example:- Inner Implementation Outer Look of a Mobile Phone, like it detail of a Mobile Phone, how keypad has a display screen and keypad buttons button and Display Screen are to dial a number. connected with each other using circuits Difference between Composition and Aggregation Composition Aggregation Defines a strong-coupled relationship Defines a weak-coupled relationship between two entities, where the one between two entities, where one entity entity is part of another, and both need could be part of another, but either can each other for their existence. exist without the other, independantly. e.g. Human body and the Heart. e.g.School and teacher. Composition implies real ownership of Aggregation does not necessarily own its components any of its aggregates. Composition has a stronger bond of its Aggregation has weaker or looser bonds components. with its aggregates. Composition has components that exist Aggregation has aggregates that live at at the inner level. the outer level.
  • 2. Difference between Private Class and Sealed Class Private Class Sealed Class A Private class can only be accessed by A Sealed class can be accessed by any the class it is defined and contain within class.Private Constructor of a Private - it is completely inaccessible to outside Class = Sealed Class. classes. In private Class,we can create a In Sealed class we can not create a constructor and therefore we can create constructor of that class, so no instance an instance of that class. of that class is possible. public class A public sealed class A { { private class B } { public class B : A //ERROR } { B b = new B(); } } public class C { A.B b = new A.B(); // ERROR } The main use of Private class is to create The sealed classes are mainly used to a user-defined type, which we want to be prevent inheritance features of object accessible to that class only. oriented programming. Private class(i.e private constructor) is also used to implement singleton classes(pattern). Singleton means "A single-instance object, and it simplify complex code. Singletons have a static property that we must access to get the object reference." Difference between Static Class and Sealed Class Static Class Sealed Class We can neither create their instances, We can create their instances, but cannot nor inherit them inherit them They can have static members only. They can contain static as well as nonstatic members. ex: ex: static class Program
  • 3. { sealed class demo { } } class abc:demo { --Wrong } Static classes are used when a class The sealed classes are mainly used to provides functionality that is not specific prevent inheritance features of object to any unique instance. oriented programming. Difference between Virtual method and Abstract method Feature Virtual method Abstract method Overriding Virtual method may or may An abstract method should be not override by inherited class. overriden by inherited class. i.e.,Virtual method provide i.e.,Abstract method forces the derived class with the the derived class to option of overriding it. override it. Virtual = = Overridable abstract == MustOverride Implementation Virtual method has an Abstract method does not implementation. provide an implementation. Necessity to Virtual methods allow Abstract methods in a Implement subclasses to provide their class contain no method own implementation of that body, and are implicitly method using the override virtual keyword Scope Virtual methods scope to Abstract method's scope to members only. members and classes Instancing Virtual methods - Not Abstract method - direcly applicable, as we can't NO, but other way, Yes. create instance for We can create an instance members, it is possible only of a class that derives from with classes. an abstract class. And we can declare a type Abstract class and instantiate that as a derived class.
  • 4. Example: public abstract class Test { public abstract void A(); // Abstract method public virtual void B() { Console.WriteLine("Test.B"); } // Virtual Method } public class InheritedTest : Test { public override void A() { Console.WriteLine("InheritedTest.A"); } //Method B implementation is optional public override void B() { Console.WriteLine("InheritedTest.B"); } } Difference between Class and Static Class Class Static Class Class has Instance Members Static class does not have Instance Members In Class, Constructor has Access In Static Class, Constructor does not Specifier. have Access Specifier. In Class Constructor, initiation is done In Static Class ,Constructor will be every time when an object is created called only one time . for the class In Class, Class members can be In Static Class, members can be accessed through class object. accessed through its Class name only
  • 5. Difference between Method Overloading and Method overriding in C# Method Overloading Method overriding Method Overloading is passing same Method Overriding is redifining parent message for different functionality class function to the child class Method Overloading is between the Method Overriding is between the same same function name with the different method. signature Method Overloading does not check for Method Overriding checks the return the return type. type. Method Overloading takes place in the Method Overriding takes place between same class. parent and child classes Method Overloading is static binding Method Overriding is a dynamic binding.