Virtual Classes Logo          Virtual Classes
    Read Anytime,Anywhere
Search *: Please select technology.



Q.1-What is Class?
A class is a blueprint or template or set of instructions to build a specific type of object. Every object is built from a class. Each class should be designed and programmed to accomplish one, and only one, thing.
Think about classes, instances, and instantiation like baking a cake. A class is like a recipe for chocolate cake. The recipe itself is not a cake. You can't eat the recipe (or at least wouldn't want to). If you correctly do what the recipe tells you to do (instantiate it) then you have an edible cake. That edible cake is an instance of the chocolate cake class. You can make as many cakes as you would like using the same chocolate cake recipe. Likewise, you can instantiate as many instances of a class as you would like.
Click here to read Class in details

Q.2-What is Object?
Objects are the building blocks of OOP and are commonly defined as variables or data structures that encapsulate behavior and data in a programmed unit. An object can be considered a "thing" that can perform a set of related activities. The set of activities that the object performs defines the object's behavior. For example, the Hand (object) can grip something, or a Student (object) can give their name or address. an object is a self-contained component that contains properties and methods needed to make a certain type of data useful. An object’s properties are what it knows and its methods are what it can do. In pure OOP terms an object is an instance of a class.
Every object is composed by:
Object identity: Means that every object is unique and can be differentiated from other objects. Each time and object is created (instantiated) the object identity is defined.
Object behavior: What the object can do. In OOP, methods work as functions that define the set of actions that the object can do.
Object state: The data stored within the object at any given moment. In OOP, fields, constants, and properties define the state of an object.
Click here to read Object in details

Q.3-What is Encapsulation in Object Orient Programming?
Encapsulation is the packing/Wrapping of information so that the imformation cann't be accessed out side the words.

In programming we can define encapsulation as,
"Encapsulation is a process of binding data members (variables, properties) and member functions (methods) into a single unit".

One can achieve encapsulation through Classes or structures. Through encapsulation a class can hide the internal details of how an object does something. A class or structure 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.
Benifit of encapsulation-
1-A supposed benefit of encapsulation is that it can reduce system complexity, and thus increase robustness
2-To hide and prevent code (data) from the outside world (here the world means other classes and assemblies).
3-To prevent code (data) from accidental corruption due to programming errors so that we can deliver expected output. Due to programming mistakes, code may not behave properly and it has an effect on data and then it will affect the functionality of the system. With encapsulation we can make variables, properties, and methods private so it is not accessible to all but accessible through proper channels only to protect it from accidental corruption from other classes.
4-To have a class better control over its fields (validating values etc…).
Click here to read Encapsulation in details

Q.4-What is Inheritance in Object Orient Programming?
In object-oriented programming (OOP),Inheritance is the process of getting the properties or behavior of one class from another class.
Inheritance is a mechanism for code reuse and to allow independent extensions of the original software via public classes and interfaces. The relationships of objects or classes through inheritance give rise to a hierarchy. inheritance only reuses implementation and establishes a syntactic relationship, not necessarily a semantic relationship (inheritance does not ensure behavioral subtyping). Class that gets the behaviour of another class is called derive class and class that give it's behavior to derive class is called base class.

Types of inheritance
1-single inheritance:In single inheritance, subclasses inherit the features of a single base class.
2-Multiple inheritance: Multiple Inheritance allows a class to have more than one base class.
3-Multilevel inheritance:In multilevel inheritance a derive class act as a base class clas for another class.
4-Hybrid inheritance:It is a mixture of all the above types of inheritance.
5-Hierarchical inheritance :In hierarchical inheritance a single class serves as a superclass (base class) for more than one sub class.
Click here to read Inheritance in details

Q.5-What is Polymorphism?
In object-oriented programming, polymorphism (from the Greek meaning "having multiple forms") is the characteristic of being able to assign a different meaning or usage to something in different contexts - specifically, to allow an entity such as a variable, a function, or an object to have more than one form.
In programming languages,polymorphism is the provision of a single interface to entities of different types. A variable with a given name may be allowed to have different forms and the program can determine which form of the variable to use at the time of execution.
Types Of Polymorphism
1-Compile Type Polymorphism
    A-Operator Overloading
    B-Function Overloading
2-Run Time Polymorphism
    A-Virtual Function
Click here to read polymorphism in details


Q.6-What is an abstract class?
In object-oriented programming, An abstract class is a class which cannot be instantiated. It is created to act as a base class for other classes. An abstract class can contain Abstract and concrete methods.
Click here to read Abstract in details

Q.7- what is constructor?
Constructor is a method used in class used to initialize the state of an object, and it gets invoked at when the object of that class is created..
Rules for constructor are:
Constructor Name should be same as class name.
Constructor must have no return type.
Click here to read Class in details

Q.8-What are the different ways for a method to be overloaded?
Function can be overloaded in following ways.
1-By passing the no of arguments to a function.
Add(int a , int b) and Add(int a, int b, int a)
2-By passing type of argument.
Add(int a , int b ) and Add(string a, string b)
3-By passing sequence of arguments passed.
Add(int a , string b ) and Add(string a, int b)
we cann't overload a function by return type of a function.
Click here to read polymorphism in details

Q.9-What is the differentiate between abstraction and encapsulation?
Abstraction is used to display only necessary and essential features of an object and hide un-necessary details to ouside the world( Outside the world means when we use reference of object then it will show only necessary methods and properties and hide methods which are not necessary.). Means displaying what is necessary and encapsulate/hide the unnecessary things to outside the world.
Hiding can be achieved by using "private" access modifiers.
where as Encapsulation is the packing/Wrapping of information so that the imformation cann't be accessed out side the words.
One can achieve encapsulation through Classes or structures. Through encapsulation a class can hide the internal details of how an object does something.
Click here to read Encapsulation in details

Q.10- What is dynamic or run time polymorphism?
In object-oriented programming,run time polymorphism is acheved by overriding a method. a virtual function or virtual method is a function or method whose behavior can be overridden within an inheriting class by a function with the same signature. This concept is an important part of the polymorphism portion of object-oriented programming (OOP).
Virtual functions allow a program to call methods that don't necessarily even exist at the moment the code is compiled.
Click here to read polymorphism in details


Q.11-Is it possible for a class to inherit the constructor of its base class?
No, A class can not inherit the constructor of it's base class.
Click here to read Class in details

Q.12-Why is the virtual keyword used in code?
The virtual keyword is used to specify that the methods and the properties of that class can be overridden in derived classes.
Click here to read polymorphism in details

Q.13-Can you allow a class to be inherited, but prevent a method from being overridden in C#?
Yes. Just declare the class as public and make the method of this class as sealed.
Click here to read polymorphism in details

Q.14-Can you explain sealed keyword?
Sealed keyword enables you to prevent specific virtual methods or properties to be overridden. means if you declare a class as sealed class then that class can not be inherited and if you define a method as sealed then that method can not be overridden.

Q.15-Can a derive class inherit private members of a class?
No, a derive class cannot inherit private members of it's base class because private members are accessible only to that class and not outside that class.
Click here to read Inheritance in details

Q.16-Can abstract have constructor?
Yes, a abstract class can have constructor, although you can not create object of that class.
Constructor in abstract class is used to initialize the variable of abstract class.
Click here to read Abstract Class in details

Q.17-What is a static constructor?
Static constructors are used to initialize the static data of a class. It is callsed before the first instance is created.

The static constructor has the following features:
1-No access specifier is required to define it.
2-You cannot pass parameters in static constructor.
3-A class can have only one static constructor.
4-It can access only static members of the class.
5-It is invoked only once, when the program execution begins.

Q.18-What is the difference between method overriding and method overloading?
In Overriding methods you can create two or more methods with the same name and same parameter in base class and it's drive classes. But it overloading you can create two or more methods with the same name but different signature. Overriding is a run time polymorphism but overloading is a compile time polyporphism.
Click here to read polymorphism in details

Q.19-What are interfaces?
Interface is a contract which has only empty methods and properties . Any class which implements the interface has to implement all the empty methods and properties of the interface. All properties and method in a interface are public by default and interface can not have constructor.
Click here to read Interface in details

Q.20-What are difference between Association,Aggregation and Composition?
Association:Association is a (*a*) relationship between two classes.
It allows one object instance to cause another to perform an action on its behalf. It represents a relationship between two or more objects where all objects have their own lifecycle and there is no ownership.
The name of an association specifies the nature of relationship between objects.

Aggregation: It is a specialized form of Association where all object have their own lifecycle but there is ownership. This represents “whole-part or a-part-of” relationship.

Composition:It is a specialized form of Aggregation. It is a strong type of Aggregation.
In this relationship child objects does not have their lifecycle without Parent object. If a parent object is deleted, all its child objects will also be deleted. This represents “death” relationship.
Click here to read Association/ Aggregation/ Composition in details


Q.21-What is instantiation?
Instantiation is when you create an object of a class. When you Instantiate a class, that class constructor is called,You need to instantiate a class before you can use it. After you instantiate your class, you can use its properties and methods.
Click here to read Object in details

Q.22-What is base and derived class?
Base Class: A Class that provides properties and methods as a foundation for a derived class. In objected-oriented programming, one class can be based on another through inheritance. Through inheritance, the base class provides characteristics (such as properties and methods) to a derived class. The derived class can either reuse or modify the members of the base class.
Derive Class:A class that based on another class (called a base class) through a technique called inheritance. A derived class inherits the members of its base class and can override or shadow base class inherited members.
Click here to read Inheritance in details

Q.23-What is Multi Level Inheritance?
In multilevel inheritance, a derive class act as a base class class for another classes. Click here to read Inheritance in details