Q. What is inheritance ?
Ans: Inheritance is a process in which one class acquires the property and method of another class class that is called inheritance

For Example

suppose we make a project for coaching center on which we insert the recoreds of teachers and student so we make a Class Person{} on which we defile all the common properties just like FirstName, LastName, MobileNo, Address etc.

Then make another calss Student{} and Teacher{} on which we inherit Person{} so all the properties and method of Person class are available on Student{} and Teacher{} class so By Using inheritance its reduce the code and reusability of code.

Q. Types of inheritance ?

  1. Single Inheritance : In Single Inheritance there will be only one base(parent) class and one derived(child) class
  2. Multiple Inheritance : In Multiple Inheritance there will be multiple base(parent) class and one derived(child) class
    • Note: In C#, multiple inheritance can only be achieved with the help of interfaces. Which means only one base class is allowed, and multiple interfaces.
  1. Multilevel inheritance:- In the Multilevel inheritance, a derived class will inherit a base class and this derived class also act as the base class for other class.
    • For Example suppose we have three classes ClassA{}, ClassB{} and ClassC{} then ClassB{} inherits ClassA{} and ClassC{} inherits ClassB{} In this situation ClassC{} inherits all the features of classA and ClassB.
  1. Hierarchal inheritance:- In this inheritance One, child class is derived more than one base class.

Q. What is Polymorphism ?

Ans:- Polymorphism means one method and there behavior is different different.

There are two types of polymorphism:

  1. Compile time(static):- Method overloading is the example of compile time Polymorphism
  2. Run time(dynamic):- Method overriding is the example of compile time Polymorphism

Method overloading:- when we have a class in which multiple method with same name that is called method overloading

We can achive Method overloading by 3 ways

i. Method name are same but numbers of parameters are different
ii. Types of parameters are different
iii. Orders of parameters are different

Method overriding :- Creating a method in derived class with same name and same number of arguments that is called Method Overriding

Note:- Method Overriding not possible in same class


Q. WHAT IS THE DIFFERENCE BETWEEN OVERLOADING AND OVERRIDING ?

  1. In Overloading method name is same but signature (number of parameters/ type etc) is different.
    But in overriding both method name and signature are same.
  2. Overloading is a type of COMPILE TIME polymorphism.
    Overriding is a type of RUN TIME polymorphism.
  3. Method overloading doesn’t need inheritance. It is possible in same class.
    Method overriding NEEDS INHERITANCE (Base class/ Derived class). It is not possible in same class.

Q. What is Abstraction ?

Ans:- Abstraction is the process to hide the internal details(business login) and showing only essential functionality to the end users.

Abstraction achived by two ways

  1. Abstract
  2. Interface

The abstract keyword is used for classes and methods:

Abstract class: is a restricted class that cannot be used to create objects (to access it, it must be inherited from another class).

Abstract method: only be used in an abstract class, and it does not have a body. The body is provided by the derived class (inherited from).


Q. Advantages of Abstraction ?
Ans.

  1. It reduces the complexity of viewing the things.
  2. Avoids code duplication and increases reusability.
  3. Increase the security of an application or program as only important details are provided to the user.

Q, What is the difference between abstract class and interface ?

1. Abstract Class contain both Declaration and Definition of method

Interface contain on Declaration of method

2. Abstract class keyword is abstract

Interface keyword is Interface

3. Abstract class contain with method, filed, constructer, static members

Interface contain only method declaration.

4. Abstract class not support multiple inheritance( but it support inheritance with one class and multiple interfaces)

Interface support multiple Inheritance

5. an abstract class method implemented by using using override keyword

An interface implemented without using override keyword


Q. What is Encapsulation ?

Encapsulation is the process of secure sensitive data its also know as data hiding.

In this below example we make both variable Name and Age is private so this variable is not accessible from other class wo we use setName() and getName() method to set value with some specific validation

Example:- Program


Q. What is access modifiers ?