Skip to content

Desi banjara

  • Lovely birthday wishes for a very special person. As you grow older may you become more wiser. Have a wonderful birthday. Birthday Wishes
  • Where ever life may take you, whatever endeavors that you choose, I will always be, so very proud of you! Birthday Wishes
  • Travel is fatal to prejudice – Mark Twain, The Innocents Abroad/Roughing It Inspirational Travel Quotes
  • “You wouldn’t worry so much about what others think of you if you realized how seldom they do.” Eleanor Roosevelt Motivational & Inspirational Quotes
  • How to fall in love? Gratitude Quote
  • Interview question: What are primitive data types in C#? C# development
  • Interview question: What is the use of “using” keyword in C#? C# development
  • One more year older.. Well, it is better to think another way you are just one more day older than yesterday. Have a lovely Birthday! Birthday Wishes

Object Oriented Programming (OOP) in C#

Posted on September 9, 2018 By DesiBanjara No Comments on Object Oriented Programming (OOP) in C#

Interview Questions- Object Oriented Programming (OOP) in C#

 

1- What is Object oriented programming?

Object-oriented programming (OOP) is a programming model based on the concept of “objects”. Objects are the real world entities which can have data and some behaviour. Data we call as attributes or fields or properties. Behaviour we call as procedures or methods or functions. Objects use functions to perform operations on the data.

Example- A Mobile phone object can have attributes like brand, model, colour etc. The same object can have some behaviour functions like clickPhoto, saveImage, deleteImage etc.


2- What is a class in C#?

A class is a blueprint of an object that contains variables for storing data and functions to perform operations on the data. It is only a logical representation of data so it don’t occupy any memory space.

To create a class, you simply use the keyword “class” followed by the class name:

class MobilePhone  {

}


3- What is Object in C#?

An object is an instance of a class. It is like a bundle of variable and methods for a particular type of real world entities. It may represent a person, a place or any item. Example:

class Employee  {

string Name;

int Age;

string Email;

}

Creation of an Employee Object by using employee class

Employee Emp1 = new Employee ();

A class will not occupy any memory space. It is just a template to create objects. When an object is created using the new operator, memory is allocated for the class in the heap.


4- What is Abstraction?

In object oriented programming methodology, Abstraction means revealing only the essential characteristics of a thing without representing the background details. It is the process of hiding the working style of an object, and showing the information of an object in an understandable manner. It lets you focus on what the object does instead of how it does it.

Abstraction provides you a generalized view of your classes or objects by providing relevant information.

In C#, “Abstraction is accomplished using an Interface. Just giving the abstract information about what it can do without specifying the details.”


5- What is encapsulation?

Encapsulation is defined ‘as the process of enclosing one or more items within a physical or logical package’. In other words, Encapsulation is a process of binding data members (variables, properties) and member functions (methods) into a single unit. And Class is the best example of encapsulation.

In object oriented programming methodology, Encapsulation prevents access to implementation details. Through encapsulation a class can hide the internal details of how an object does something. A class can specify how accessible each of its members (variables, properties, and methods) is to code outside of the class or structure. Encapsulation simplifies the interaction between objects. An object can use another object without knowing all its data or how its data is maintained.

Example, an employee object might have name, address, and payroll properties. If a HR object wants to know the employee basic details (name and address), it can request the name and address for the employee without needing to know the payment details of the employee object.

A class uses access modifiers to accomplish the data hiding. These access modifiers are: public, private, protected, internal, and protected internal.


Explain various Access Modifiers in C#.

Access Modifiers describes accessibility of an Object and its members. We can control the accessibility of the member object of a class using access modifiers.

C# provide five access specifiers:

public: public can be access from anywhere that means there is no restriction on accessibility. The scope of the accessibility is inside class as well as outside. The type or member can be accessed by any other code in the same assembly or another assembly that references it.

private: The scope of the accessibility is limited only inside the classes or struct in which they are declared. The private members cannot be accessed outside the class and it is the least permissive access level.

protected: The scope of accessibility is limited within the class or struct and the class derived (Inherited) from this class. It means object of derived class can access the protected member of base class.

internal: The internal access modifiers can access within the program that contain its declarations and also access within the same assembly level but not from another assembly.

protected internal:

Protected internal is the mix access levels of both protected and internal. It can access anywhere in the same assembly and in the same class also the classes inherited from that class.



6- What is Inheritance in Object oriented programming?

Inheritance is one of the most important concepts in object-oriented programming. It is the ability to create a class that inherits attributes and behaviors from an existing class.

In other words, by using inheritance we can define parent class and child class. The child class inherits methods and properties of the parent class, but at the same time, they can also modify the behavior of the methods (method overriding) if required. Inheritance is a concept of code reusability.

7- What is Polymorphism in Object oriented programming?

Polymorphism is one of the fundamental concepts of object-oriented programming. Polymorphism is a Greek word that is created from two words: poly and morphos. The word poly means many and morphos means forms. In other words, “Many forms of a single object is called Polymorphism.”

Object oriented programming uses Polymorphism for using same operator or function with different types of operand and parameters. It means you can define same name method with different number and type of parameters.

There are two types of Polymorphism in C#

  • Static Polymorphism
  • Function overloading
  • Operator overloading
  • Dynamic Polymorphism

Dynamic Polymorphism can be achieved by using abstract classes and function overriding.

C# development, Interview questions, IT/Software development Tags:C#, C# development, Encapsulation, Inheritance, Interview questions, object oriented programming, object oriented programming methodology, OOP, Polymorphism

Post navigation

Previous Post: SOLID Design Principles
Next Post: ASP.Net MVC Interview Questions

Related Posts

  • Interview question: What are dynamic type variables in C#? C# development
  • Interview question: In c#, How can we create a function which can accept varying number of arguments? C# development
  • Interview question: What is encapsulation? C# development
  • Interview question: What is C#? C# development
  • Asp.Net WebApi Interview Questions ASP.NET Web API
  • Interview question: What are nullable types in C#? C# development

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *



Archives

  • February 2023
  • February 2022
  • June 2021
  • March 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • July 2020
  • June 2020
  • April 2020
  • December 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • June 2018
  • May 2018
  • April 2018
  • January 2018
  • September 2017
  • August 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • August 2015
  • May 2015
  • April 2014
  • November 2013

Categories

  • Acer
  • Amazon AWS Certification Exam
  • Amazon Kindle
  • Android phones
  • ASP.Net MVC
  • ASP.NET Web API
  • AWS DevOps Engineer Professional Exam
  • AZ-300: Microsoft Azure Architect Technologies Exam
  • Azure Active Directory
  • Azure App Services
  • Azure Data Factory
  • Azure Logic Apps
  • Azure Mobile Apps
  • Azure Virtual Machine
  • Best Wishes Messages
  • birthday messages for boyfriend
  • Birthday messages For Girlfriend
  • Birthday Wishes
  • Birthday Wishes For Mom
  • Business
  • C# development
  • Cameras
  • Canon
  • Cloud
  • Cloud services
  • digital-cameras
  • Diwali
  • Entrepreneurship
  • eReaders
  • Family Quotes
  • Family Quotes
  • Friendship Quotes
  • Gadgets
  • Games
  • Get Well Soon Messages
  • GIT
  • Good Morning Wishes
  • Google
  • Gratitude Quote
  • Guru Nanak Jayanti
  • Halloween
  • Happiness Quote
  • Happy Diwali Wishes
  • Happy Independence Day Wishes
  • Happy New Year Wishes
  • HTC
  • HTC One
  • HTML
  • I Miss You Messages
  • Inspirational Quotes
  • Inspirational Travel Quotes
  • Interview questions
  • IT/Software development
  • Leadership Quote
  • Life lessons
  • Love Quotes
  • Love shayari
  • Messages
  • Microsoft AI-900 Certification Exam
  • Microsoft AZ-104 Certification Exam
  • Microsoft AZ-204 Certification Exam
  • Microsoft AZ-900 Certification Exam
  • Microsoft Azure
  • Microsoft Azure certifications
  • Microsoft Exam AZ-220
  • Microsoft Excel
  • Microsoft Office
  • Microsoft word
  • Mobile phones
  • Motivational & Inspirational Quotes
  • Nature Quotes
  • Nexus
  • Nikon
  • Pixels
  • PL-200: Microsoft Power Platform Functional Consultant Certification
  • PL-900: Microsoft Power Platform Fundamentals
  • postman
  • Quotes
  • Robin Sharma
  • Samsung Galaxy S5
  • Self improvement quotes
  • Self-Confidence Quote
  • SonarQube
  • Sony PlayStation 4
  • SQL
  • SQL Server
  • Success Quotes
  • Travel Quotes
  • Uncategorized
  • Uplifting Quotes
  • WCF (Windows Communication Foundation)
  • Web development
  • Wishes
  • Wishes for Newborn Baby

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org



Recent Posts

  • Azure Data Factory
  • What is Azure Active Directory?
  • Azure Virtual Machine
  • Azure Logic Apps
  • Azure Mobile Apps

Recent Comments

  • Yosianus on Error while sending json model in POST request to web API service using postman
  • AWS DevOps Engineer Professional Exam Practice Questions Amazon AWS Certification Exam
  • Microsoft AZ-900 Certification Exam Practice Questions – 3 Microsoft AZ-900 Certification Exam
  • “The bravest sight in the world is to see a great man struggling against adversity.”– Seneca Motivational & Inspirational Quotes
  • “Next to trying and winning, the best thing is trying and failing.”– L.M. Montgomery Motivational & Inspirational Quotes
  • Today is when you can expect anything from us. Giving it is our choice! Birthday Wishes
  • “Confidence comes not from always being right but from not fearing to be wrong.” Peter T. Mcintyre Motivational & Inspirational Quotes
  • “Things turn out the best for the people who make the best of the way things turn out.”-John Wooden Motivational & Inspirational Quotes
  • It is your birthday. Time to light the candles on the cake and enjoy the day with lots of fun and laughter. Wishing you a very happy birthday. Birthday Wishes

Copyright © 2023 Desi banjara.

Powered by PressBook News WordPress theme