Sunday, October 11, 2009

OOPS - Part - 3

1) How do you refer to a member in the base class?
To refer to a member in the base class use:return base.NameOfMethod().

2) In terms of constructors, what is the difference between: public MyDerived() : base() an public MyDerived() in a child class?

3) What is the default accessibility for a class?
internal for a top level class, private for a nested one.

4) What is an out parameter? What is difference between out and ref parameter?
An out parameter allows an instance of a parameter object to be made inside a method. Reference parameters must be initialised but out gives a reference to an uninstanciated object.

5) What is polymorphism?
Polymorphism is the ability to implement the same operation many times. Each derived method implements the operation inherited from the base class in its own way.

6) Can abstract methods override virtual methods?

7) What are attributes?
Attributes are declarative tags which can be used to mark certain entities (like methods for example).

Tuesday, March 31, 2009

OOPS - Part 2

1) What is public accessibility?
There are no access restrictions.

2) What is private accessibility?
Access is restricted to within the containing class.

3) Methods must declare a return type, what is the keyword used when nothing is returned from the method?

4) What are the two return types for main?
void and int

5) What is a reference and value parameter?
Reference parameters reference the original object whereas value parameters make a local copy and do not affect the original.

6) How do you refer to a member in the base class?
To refer to a member in the base class use:return base.NameOfMethod().

7) What does new do in terms of objects?
Initializes an object.

8) What is the difference between the new operator and modifier?
The new operator creates an instance of a class whereas the new modifier is used to declare a method with the same name as a method in one of the parent classes.

9) Can an interface have properties?

10) What is a nested class?
A class declare within a class.

11) What is a namespace?
A namespace declares a scope which is useful for organizing code and to distinguish one type from another.

12) Can nested classes use any of the 5 types of accessibility?

13) Does C# supports multiple inheritance?

In C#, a class can inherite only one class. But how ever multiple inheritance can be simulated by implementing more than one interfaces.

14) Can different assemblies share internal access?

'internal' accessibility refers that the member can be accessed within the same assembly.

15) Can you inherit from multiple interfaces?
Yes (Actually its not inheriting, its implementing).

16) What keyword would you use for scope name clashes?
this (me - for Vb.Net).

17) Can you have nested namespaces?

18) Can you prevent your class from being inherited by another class?
Yes. The keyword “sealed” will prevent the class from being inherited.

19) What is protected accessibility?
Access is restricted to types derived from the containing class.

20) What is internal accessibility?
Accessible from files within the same assembly.

21) What is protected internal accessibility?
Access is restricted to types derived from the containing class or from files within the same assembly.

22) What is the default accessibility for members of an interface?
(Note: No accessibility can be mentioned; even public.)

23) What is the default accessibility for members of a struct?

24) Class methods/members to should be marked with what keyword?

25) A class can have many mains, how does this work?
Only one of them is run, that is the one marked (public) static. (Note: no object need to call this method since it’s a static.)

26) If I have a constructor with a parameter, do I need to explicitly create a default constructor?

27) Can you use access modifiers with destructors?

28) What is boxing and unboxing?
Converting a value type (stack->heap) to a reference type (heap->stack), and vise-versa.

29) What is a pointer?
A pointer is a reference to a memory address.

30) In terms of references, how do == and != (not overridden) work?
They check to see if the references both point to the same object.

31) Can assignment operators be overloaded directly?

32) What operators cannot be overloaded?
=, ., ?:, ->, new, is, sizeof, typeof

33) What is early and late binding?
Late binding is using System.object instead of explicitly declaring a class (which is early binding).

34) Can base constructors can be private?

Sunday, March 29, 2009

OOPS - Part 1

1) What is meant by Object Oriented Programming?
OOP is a method of programming in which programs are organized as cooperative collections of objects. Each object is an instance of a class and each class belong to a hierarchy.

2) What is a Class?
Class is a template for a set of objects that share a common structure and a common behaviour.

It’s a comprehensive data type which represents a blue print
of objects. It’s a template of object.

3) What is an Object?
Object is an instance of a class. It has state,behaviour and identity. It is also called as an instance of a class.

It is a basic unit of a system. An object is an entity that has attributes, behavior, and
identity. Objects are members of a class. Attributes and behavior of an object are defined
by the class definition.

4) What is an Instance?
An instance has state, behaviour and identity. The structure and behaviour of similar classes are defined in their common class. An instance is also called as an object.

5) What are the core OOP’s concepts?
Abstraction, Encapsulation,Inheritance and Polymorphism are the core OOP’s concepts.

6) What is meant by abstraction?
Abstraction defines the essential characteristics of an object that distinguish it from all other kinds of objects. Abstraction provides crisply-defined conceptual boundaries relative to the perspective of the viewer. Its the process of focussing on the essential characteristics of an object. Abstraction is one of the fundamental elements of the object model.

7) What is meant by Encapsulation?
It is a process of hiding all the internal details of an object from the outside world.

Encapsulation is the process of compartmentalising the elements of an abtraction that defines the structure and behaviour. Encapsulation helps to separate the contractual interface of an abstraction and implementation.

8) What is meant by Inheritance?
Inheritance is a relationship among classes, wherein one class shares the structure or behaviour defined in another class. This is called Single Inheritance. If a class shares the structure or behaviour from multiple classes, then it is called Multiple Inheritance. Inheritance defines “is-a” hierarchy among classes in which one subclass inherits from one or more generalised superclasses.

Hierarchy is used to define more specialized classes based on a preexisting generalized
class which will add new attributes and use some existing qualities
of the parent class. Its shows more of a parent-child relationship. This kind of hierarchy
is called inheritance.

9) What is meant by Polymorphism?
Polymorphism literally means taking more than one form. Polymorphism is a characteristic of being able to assign a different behavior or value in a subclass, to something that was declared in a parent class.

10) What is an Abstract Class?
Abstract class is a class that has no instances. An abstract class is written with the expectation that its concrete subclasses will add to its structure and behaviour, typically by implementing its abstract operations.

11) What is an Interface?
Interface is an outside view of a class or object which emphaizes its abstraction while hiding its structure and secrets of its behaviour.

12) What is the difference between abstract class and interface?
i)Abstract classes can have concrete methods while interfaces have no methods
ii) Interfaces do not come in inheriting chain, while abstract classes come in

We use abstract class and interface where two or more entities do same type of work but in different ways. Means the way of functioning is not clear while defining abstract class or interface. When functionality of each task is not clear then we define interface. If functionality of some task is clear to us but there exist some functions whose functionality differs object by object then we declare abstract class.

13) What is a base class?
Base class is the most generalised class in a class structure. Most applications have such root classes. In Java, Object is the base class for all classes.

14) What is a subclass?
Subclass is a class that inherits from one or more classes

15) What is a superclass?
superclass is a class from which another class inherits.

16) What is a constructor?
Constructor is an operation that creates an object and/or initialises its state.

17) What is a destructor?
Destructor is an operation that frees the state of an object and/or destroys the object itself. In Java, there is no concept of destructors. Its taken care by the JVM.

18) What is meant by static binding?
Static binding is a binding in which the class association is made during compile time. This is also called as Early binding.

19) What is meant by Dynamic binding?
Dynamic binding is a binding in which the class association is not made until the object is created at execution time. It is also called as Late binding.

20) What does virtual keyword mean ?
They signify that method and property can be overridden.

21) what is Method Overloading?
Method Overloading means to have two or more methods in the same class with different signature. The benefit of method overloading is that it allows you to implement methods that supports the same semantic operation but differ by argument number or type.

22) What is Method Overriding?
Method Overriding changing the behavior of a method in a base class. Use keyword Overrides.

23) What is meant by Binding?
Binding denotes association of a name with a class.

24) What is a delegate ?
Delegate is a class that can hold a reference to a method or a function. Delegate class has
a signature and it can only reference those methods whose signature is compliant with the
class. Delegates are type-safe functions pointers or callbacks.

25) Do interface have accessibility modifier?
All elements in Interface should be public. So by default all interface elements are public
by default.

26) What is meant by Persistence?
Persistence is the property of an object by which its existence transcends space and time.

27) What is colloboration?
Colloboration is a process whereby several objects cooperate to provide some higher level behaviour.