C# Oops

interview question

What are the main concepts of oops ?

1.Object

2.Class

3.Inheritance

4.Polymorphism

5.Abstraction

6.Encapsulation

Piller of oops?

1.Inheritance

2.Polymorphism

3.Abstraction

4.Encapsulation

What is a Class:

A class is a LOGICAL UNIT or BLUEPRINT that contains methods ,fieldsand properties. Class member are.

What is a Constructor?

Constructor ois a method in the class which gets executed when a class object is created.

OR

Constructor is a spacial method which has same name as a class name and it is used to initialize member variable of the class.

What is a Field :-

A field is a variable of any type. it is basically the data.

What is Property:-

A property is a member that provides that helps in read and write of private field.

What is a Method:-

A Method is a code of block that contains of statements.

What is a Object :-

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace PraticeOOPS { class Employee //class { public Employee() // Constructor {

} private int experience; //field public int Experience //property { get { return experience; } set { experience = value; } } public void CalculateSalary() // Method { int salary = Experience * 3000; Console.WriteLine("salary:{0}", salary); } }

internal class Q1 { static void Main() { Employee emp = new Employee(); // Colling object emp.Experience = 3; emp.CalculateSalary(); } } }

What is inheritance:-

Getting the property existing class to new class is call inheritance it is use to code reusebilti

or

Inheritance is creating a parent-Child relationship between two classes where child class will automatically get the properties and method of the parent.

Types of Inherytance:-

  1. Single Inheritance

  2. Multiple Inheritance

  3. MultiLevel Inheritance

  4. Hierarchial Inheritance

  5. hybrid Inheritance ( it is not posible )

Single Inheritance:-

Multiple Inheritance:-

MultiLevel Inheritance:-

Hierarchial Inheritance:-