Monday, July 20, 2009

OOPS FAQ

What are the main properties of object oriented programming?
a) There are mainly 3 properties1. Encapsulation/Abstraction2. Inheritance3. Polymorphism

What is encapsulation?
a) This gives a way to hide the internal details of an object from its users.

3. What is inheritance ?a ) It provides a way to build/create new classes using existing classes.

4. What is polymorphism?
a) It provides a way to take more than one form.

5. What is a constructor?a ) Constructor enables an object to initialize itself when it is first created.

6. What are the properties of a constructor?a ) They are1. They should have the same name as that of a class2. They do not specify a return type.3. we can use access modifiers to constructor.

What are the differences between an abstract class and an interface?
a) Abstract class
1. it can contain implementation to some methods.
2. we can apply access modifiers to one or more methods in an abstract class
3. a class can not inherit more than one abstract class
4. an abstract class can have fields and constants defined
Interface
1. it just contains declarations. No implementation for any method.
2. we can not apply access modifiers to methods inside an interface
3. a class can inherit more than one interface
4. interface does not contain any field definition.


What are the types of polymorphism?
a) 2 types
1. operation polymorphism
2. inclusion polymorphism


What are the abstract classes?
a) Abstract classes are the classes for which we can not create objects. Means an abstract class can not be instantiated.

What are abstract methods?
a) Abstract methods are the methods which does not contain their body part means they does not provide any implementation.

What are the properties of abstract methods?
a) 1. they do not contain body part.2. their definition/implementation should be given in non-abstract classes by overriding that method.3. we can not use static modifier to it.

What are the sealed classes?
a) If you want to prevent a class from being inherited you can use this keyword sealed to that particular class

39. What are sealed methods?
a) A sealed method is a method which can not be overridden by its derived class.

40. Does a sealed class is an abstract class? Why?
a) No a sealed class is not an abstract class. Because we can’t inherit a sealed class but we can inherit an abstract class.

Differences between overloading and overriding?
a) Overloading1. used we want a method with more than one definition with in the same scope2. in overloading, methods will have same name but different number, types, order of arguments.Overriding1. this is used when we have parent, child classes.2. in overriding , methods will have same name with same arguments and same return type.

How many static constructors we can declare for a single class?
a) A class can have only one static constructor.

What is method overloading?
a) It is a process of creating methods that have the same name but with different parameter lists and different definitions. This method overloading is used when you want your methods to do same tasks but using different input parameters.

What are instant variables?
a) Class variables are known as instant variables. Instant variables are different for each object and they are accessed using the objects. When ever a class is instantiated a new copy of the each of the instant variable is created.

What are static variables?
a ) These are also known as class variables. Static variables are common for all objects of a class. Only one copy of static variables will be created for all the objects of a class.

What are the differences between structure and classa ) Structure:It is value typeIt is stored on stackDoes not support inheritanceSuitable for small data structureClass:It is reference typeIt is stored on heapSupports inheritanceSuitable for complex data structures

What is a value type? Give examplesa )
It stores value directly. Value types are stored on stack. Separate memory will be given for each instant of a value type.Ex: int, float, char, struct

What are reference type?
a) It stores a reference to the value. They are stored on heap.Ex: class, string, array.


string strHobbies = string.Empty;
foreach (ListItem chk in CheckBoxList1.Items)
{
if (chk.Selected)
{
if (string.IsNullOrEmpty(strHobbies))
{
strHobbies = chk.Value;
}
else
{
strHobbies = strHobbies + "," + chk.Value;
}
}
}
objInsert._Hobbies = strHobbies;


if (FileUpload1.HasFile)
{
objInsert._Image = strImageId + "_" + Convert.ToString(FileUpload1.FileName);
FileUpload1.SaveAs(Server.MapPath(ConfigurationManager.AppSettings["imageUrl"].ToString()) + objInsert._Image);
}

No comments:

Post a Comment