Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Search Your Question

Showing posts with label Object Oriented Application Development. Show all posts
Showing posts with label Object Oriented Application Development. Show all posts

Monday, May 19, 2008

Object Oriented Interview Questions

What do you mean by analysis and design?
Analysis:
Basically, it is the process of determining what needs to be done before how it should be done. In order to accomplish this, the developer refers the existing systems and documents. So, simply it is an art of discovery.
Design:
It is the process of adopting/choosing the one among the many, which best accomplishes the users needs. So, simply, it is compromising mechanism.

What are the steps involved in designing?
Before getting into the design the designer should go through the SRS prepared by the System Analyst.
The main tasks of design are Architectural Design and Detailed Design.
In Architectural Design we find what are the main modules in the problem domain.
In Detailed Design we find what should be done within each module.

What are the main underlying concepts of object orientation?
Objects, messages, class, inheritance and polymorphism are the main concepts of object orientation.

What do u meant by "SBI" of an object?
SBI stands for State, Behavior and Identity. Since every object has the above three.
• State:
It is just a value to the attribute of an object at a particular time.
• Behaviour:
It describes the actions and their reactions of that object.
• Identity:
An object has an identity that characterizes its own existence. The identity makes it possible to distinguish any object in an unambiguous way, and independently from its state.

Differentiate persistent & non-persistent objects?
Persistent refers to an object's ability to transcend time or space. A persistent object stores/saves its state in a permanent storage system with out losing the information represented by the object.
A non-persistent object is said to be transient or ephemeral. By default objects are considered as non-persistent.

What do you meant by active and passive objects?
Active objects are one which instigate an interaction which owns a thread and they are responsible for handling control to other objects. In simple words it can be referred as client.
Passive objects are one, which passively waits for the message to be processed. It waits for another object that requires its services. In simple words it can be referred as server.

Diagram:
client server
(Active) (Passive)

What is meant by software development method?
Software development method describes how to model and build software systems in a reliable and reproducible way. To put it simple, methods that are used to represent ones' thinking using graphical notations.

What are models and meta models?
Model:
It is a complete description of something (i.e. system).
Meta model:
It describes the model elements, syntax and semantics of the notation that allows their manipulation.

What do you meant by static and dynamic modeling?
Static modeling is used to specify structure of the objects that exist in the problem domain. These are expressed using class, object and USECASE diagrams.
But Dynamic modeling refers representing the object interactions during runtime. It is represented by sequence, activity, collaboration and statechart diagrams.

How to represent the interaction between the modeling elements?
Model element is just a notation to represent (Graphically) the entities that exist in the problem domain. e.g. for modeling element is class notation, object notation etc.
Relationships are used to represent the interaction between the modeling elements.
The following are the Relationships.

• Association: Its' just a semantic connection two classes.
e.g.:

• Aggregation: Its' the relationship between two classes which are related in the fashion that master and slave. The master takes full rights than the slave. Since the slave works under the master. It is represented as line with diamond in the master area.
ex:
car contains wheels, etc.
car

• Containment: This relationship is applied when the part contained with in the whole part, dies when the whole part dies.
It is represented as darked diamond at the whole part.
example:
class A{
//some code
};

class B
{
A aa; // an object of class A;
// some code for class B;
};
In the above example we see that an object of class A is instantiated with in the class B. so the object class A dies when the object class B dies.we can represnt it in diagram like this.

• Generalization: This relationship used when we want represents a class, which captures the common states of objects of different classes. It is represented as arrow line pointed at the class, which has captured the common states.

• Dependency: It is the relationship between dependent and independent classes. Any change in the independent class will affect the states of the dependent class.
DIAGRAM:
class A class B

Why generalization is very strong?
Even though Generalization satisfies Structural, Interface, Behaviour properties. It is mathematically very strong, as it is Antisymmetric and Transitive.
Antisymmetric: employee is a person, but not all persons are employees. Mathematically all As’ are B, but all Bs’ not A.
Transitive: A=>B, B=>c then A=>c.
A. Salesman.
B. Employee.
C. Person.
Note: All the other relationships satisfy all the properties like Structural properties, Interface properties, Behaviour properties.

Differentiate Aggregation and containment?
Aggregation is the relationship between the whole and a part. We can add/subtract some properties in the part (slave) side. It won't affect the whole part.
Best example is Car, which contains the wheels and some extra parts. Even though the parts are not there we can call it as car.
But, in the case of containment the whole part is affected when the part within that got affected. The human body is an apt example for this relationship. When the whole body dies the parts (heart etc) are died.

Can link and Association applied interchangeably?
No, You cannot apply the link and Association interchangeably. Since link is used represent the relationship between the two objects.
But Association is used represent the relationship between the two classes.
link :: student:Abhilash course:MCA
Association:: student course

what is meant by "method-wars"?
Before 1994 there were different methodologies like Rumbaugh, Booch, Jacobson, Meyer etc who followed their own notations to model the systems. The developers were in a dilemma to choose the method which best accomplishes their needs. This particular span was called as "method-wars"

Whether unified method and unified modeling language are same or different?
Unified method is convergence of the Rumbaugh and Booch.
Unified modeling lang. is the fusion of Rumbaugh, Booch and Jacobson as well as Betrand Meyer (whose contribution is "sequence diagram"). Its' the superset of all the methodologies.

Who were the three famous amigos and what was their contribution to the object community?
The Three amigos namely,
• James Rumbaugh (OMT): A veteran in analysis who came up with an idea about the objects and their Relationships (in particular Associations).
• Grady Booch: A veteran in design who came up with an idea about partitioning of systems into subsystems.

• Ivar Jacobson (Objectory): The father of USECASES, who described about the user and system interaction.

Differentiate the class representation of Booch, Rumbaugh and UML?
If you look at the class representaiton of Rumbaugh and UML, It is some what similar and both are very easy to draw.
Representation: OMT UML.
Diagram:

Booch: In this method classes are represented as "Clouds" which are not very easy to draw as for as the developer's view is concern.
Diagram:

What is an USECASE? Why it is needed?
A Use Case is a description of a set of sequence of actions that a system performs that yields an observable result of value to a particular action.
In SSAD process <=> In OOAD USECASE. It is represented elliptically.
Representation:

Who is an Actor?
An Actor is someone or something that must interact with the system.In addition to that an Actor initiates the process(that is USECASE).
It is represented as a stickman .

What is guard condition?
Guard condition is one, which acts as a firewall. The access from a particular object can be made only when the particular condition is met.
For Example,
customer check customer number ATM.
Here the object on the customer accesses the ATM facility only when the guard condition is met.

Differentiate the following notations?
I: :obj1 :obj2

II: :obj1 :obj2


In the above representation I, obj1 sends message to obj2. But in the case of II the data is transferred from obj1 to obj2.

USECASE is an implementation independent notation. How will the designer give the implementation details of a particular USECASE to the programmer?
This can be accomplished by specifying the relationship called "refinement” which talks about the two different abstraction of the same thing.
Or example,

calculate pay calculate

class1 class2 class3

Suppose a class acts an Actor in the problem domain, how to represent it in the static model?
In this scenario you can use “stereotype”. Since stereotype is just a string that gives extra semantic to the particular entity/model element. It is given with in the << >>.

class A
<<>>
attributes

methods.

Why does the function arguments are called as "signatures"?
The arguments distinguish functions with the same name (functional polymorphism). The name alone does not necessarily identify a unique function. However, the name and its arguments (signatures) will uniquely identify a function.
In real life we see suppose, in class there are two guys with same name, but they can be easily identified by their signatures. The same concept is applied here.
ex:
class person
{
public:
char getsex();
void setsex(char);
void setsex(int);
};
In the above example we see that there is a function setsex() with same name but with different signature.

net Framework OOPS

1. What are the OOPS concepts?
1) Encapsulation: It is the mechanism that binds together code and data in manipulates, and keeps both safe from outside interference and misuse. In short it isolates a particular code and data from all other codes and data. A well-defined interface controls the access to that particular code and data.
2) Inheritance: It is the process by which one object acquires the properties of another object. This supports the hierarchical classification. Without the use of hierarchies, each object would need to define all its characteristics explicitly. However, by use of inheritance, an object need only define those qualities that make it unique within its class. It can inherit its general attributes from its parent. A new sub-class inherits all of the attributes of all of its ancestors.
3) Polymorphism: It is a feature that allows one interface to be used for general class of actions. The specific action is determined by the exact nature of the situation. In general polymorphism means "one interface, multiple methods", This means that it is possible to design a generic interface to a group of related activities. This helps reduce complexity by allowing the same interface to be used to specify a general class of action. It is the compiler's job to select the specific action (that is, method) as it applies to each situation.
2. What is the difference between a Struct and a Class?
o The struct type is suitable for representing lightweight objects such as Point, Rectangle, and Color. Although it is possible to represent a point as a class, a struct is more efficient in some scenarios. For example, if you declare an array of 1000 Point objects, you will allocate additional memory for referencing each object. In this case, the struct is less expensive.
o When you create a struct object using the new operator, it gets created and the appropriate constructor is called. Unlike classes, structs can be instantiated without using the new operator. If you do not use new, the fields will remain unassigned and the object cannot be used until all of the fields are initialized.
o It is an error to declare a default (parameterless) constructor for a struct. A default constructor is always provided to initialize the struct members to their default values.
o It is an error to initialize an instance field in a struct.
o There is no inheritance for structs as there is for classes. A struct cannot inherit from another struct or class, and it cannot be the base of a class. Structs, however, inherit from the base class Object. A struct can implement interfaces, and it does that exactly as classes do.
o A struct is a value type, while a class is a reference type.
3. Value type & reference types difference? Example from .NET. Integer & struct are value types or reference types in .NET?
Most programming languages provide built-in data types, such as integers and floating-point numbers, that are copied when they are passed as arguments (that is, they are passed by value). In the .NET Framework, these are called value types. The runtime supports two kinds of value types:
• Built-in value types
The .NET Framework defines built-in value types, such as System.Int32 and System.Boolean, which correspond and are identical to primitive data types used by programming languages.
• User-defined value types
Your language will provide ways to define your own value types, which derive from System.ValueType. If you want to define a type representing a value that is small, such as a complex number (using two floating-point numbers), you might choose to define it as a value type because you can pass the value type efficiently by value. If the type you are defining would be more efficiently passed by reference, you should define it as a class instead.
Variables of reference types, referred to as objects, store references to the actual data. This following are the reference types:
• class
• interface
• delegate
This following are the built-in reference types:
• object
• string
4. What is Inheritance, Multiple Inheritance, Shared and Repeatable Inheritance?
**
5. What is Method overloading?
Method overloading occurs when a class contains two methods with the same name, but different signatures.
6. What is Method Overriding? How to override a function in C#?
Use the override modifier to modify a method, a property, an indexer, or an event. An override method provides a new implementation of a member inherited from a base class. The method overridden by an override declaration is known as the overridden base method. The overridden base method must have the same signature as the override method.
You cannot override a non-virtual or static method. The overridden base method must be virtual, abstract, or override.
7. Can we call a base class method without creating instance?
Its possible If its a static method.
Its possible by inheriting from that class also.
Its possible from derived classes using base keyword.
8. You have one base class virtual function how will call that function from derived class?
Ans:

9. class a
10. {
11. public virtual int m()
12. {
13. return 1;
14. }
15. }
16. class b:a
17. {
18. public int j()
19. {
20. return m();
21. }
}
22. In which cases you use override and new base?
Use the new modifier to explicitly hide a member inherited from a base class. To hide an inherited member, declare it in the derived class using the same name, and modify it with the new modifier.
C# Language features
23. What are Sealed Classes in C#?
The sealed modifier is used to prevent derivation from a class. A compile-time error occurs if a sealed class is specified as the base class of another class. (A sealed class cannot also be an abstract class)
24. What is Polymorphism? How does VB.NET/C# achieve polymorphism?
**
25. class Token
26. {
27. public string Display()
28. {
29. //Implementation goes here
30. return "base";
31. }
32. }
33. class IdentifierToken:Token
34. {
35. public new string Display() //What is the use of new keyword
36. {
37. //Implementation goes here
38. return "derive";
39. }
40. }
41. static void Method(Token t)
42. {
43. Console.Write(t.Display());
44. }
45. public static void Main()
46. {
47. IdentifierToken Variable=new IdentifierToken();
48. Method(Variable); //Which Class Method is called here
49. Console.ReadLine();
50. }
51. For the above code What is the "new" keyword and Which Class Method is
52. called here
A: it will call base class Display method
53. class Token
54. {
55. public virtual string Display()
56. {
57. //Implementation goes here
58. return "base";
59. }
60. }
61. class IdentifierToken:Token
62. {
63. public override string Display() //What is the use of new keyword
64. {
65. //Implementation goes here
66. return "derive";
67. }
68. }
69. static void Method(Token t)
70. {
71. Console.Write(t.Display());
72. }
73. public static void Main()
74. {
75. IdentifierToken Variable=new IdentifierToken();
76. Method(Variable); //Which Class Method is called here
77. Console.ReadLine();
78. }
79. A: Derive
80. In which Scenario you will go for Interface or Abstract Class?
Interfaces, like classes, define a set of properties, methods, and events. But unlike classes, interfaces do not provide implementation. They are implemented by classes, and defined as separate entities from classes. Even though class inheritance allows your classes to inherit implementation from a base class, it also forces you to make most of your design decisions when the class is first published.
Abstract classes are useful when creating components because they allow you specify an invariant level of functionality in some methods, but leave the implementation of other methods until a specific implementation of that class is needed. They also version well, because if additional functionality is needed in derived classes, it can be added to the base class without breaking code.
Interfaces vs. Abstract Classes
Feature Interface Abstract class
Multiple inheritance A class may implement several interfaces. A class may extend only one abstract class.
Default implementation An interface cannot provide any code at all, much less default code. An abstract class can provide complete code, default code, and/or just stubs that have to be overridden.
Constants Static final constants only, can use them without qualification in classes that implement the interface. On the other paw, these unqualified names pollute the namespace. You can use them and it is not obvious where they are coming from since the qualification is optional. Both instance and static constants are possible. Both static and instance intialiser code are also possible to compute the constants.
Third party convenience An interface implementation may be added to any existing third party class. A third party class must be rewritten to extend only from the abstract class.
is-a vs -able or can-do Interfaces are often used to describe the peripheral abilities of a class, not its central identity, e.g. an Automobile class might implement the Recyclable interface, which could apply to many otherwise totally unrelated objects. An abstract class defines the core identity of its descendants. If you defined a Dog abstract class then Damamation descendants are Dogs, they are not merely dogable. Implemented interfaces enumerate the general things a class can do, not the things a class is.
Plug-in You can write a new replacement module for an interface that contains not one stick of code in common with the existing implementations. When you implement the interface, you start from scratch without any default implementation. You have to obtain your tools from other classes; nothing comes with the interface other than a few constants. This gives you freedom to implement a radically different internal design. You must use the abstract class as-is for the code base, with all its attendant baggage, good or bad. The abstract class author has imposed structure on you. Depending on the cleverness of the author of the abstract class, this may be good or bad. Another issue that's important is what I call "heterogeneous vs. homogeneous." If implementors/subclasses are homogeneous, tend towards an abstract base class. If they are heterogeneous, use an interface. (Now all I have to do is come up with a good definition of hetero/homogeneous in this context.) If the various objects are all of-a-kind, and share a common state and behavior, then tend towards a common base class. If all they share is a set of method signatures, then tend towards an interface.
Homogeneity If all the various implementations share is the method signatures, then an interface works best. If the various implementations are all of a kind and share a common status and behavior, usually an abstract class works best.
Maintenance If your client code talks only in terms of an interface, you can easily change the concrete implementation behind it, using a factory method. Just like an interface, if your client code talks only in terms of an abstract class, you can easily change the concrete implementation behind it, using a factory method.
Speed Slow, requires extra indirection to find the corresponding method in the actual class. Modern JVMs are discovering ways to reduce this speed penalty. Fast
Terseness The constant declarations in an interface are all presumed public static final, so you may leave that part out. You can't call any methods to compute the initial values of your constants. You need not declare individual methods of an interface abstract. They are all presumed so. You can put shared code into an abstract class, where you cannot into an interface. If interfaces want to share code, you will have to write other bubblegum to arrange that. You may use methods to compute the initial values of your constants and variables, both instance and static. You must declare all the individual methods of an abstract class abstract.
Adding functionality If you add a new method to an interface, you must track down all implementations of that interface in the universe and provide them with a concrete implementation of that method. If you add a new method to an abstract class, you have the option of providing a default implementation of it. Then all existing code will continue to work without change.
81. see the code
82. interface ICommon
83. {
84. int getCommon();
85. }
86. interface ICommonImplements1:ICommon
87. {
88. }
89. interface ICommonImplements2:ICommon
90. {
91. }
92. public class a:ICommonImplements1,ICommonImplements2
93. {
}
How to implement getCommon method in class a? Are you seeing any problem in the implementation?
Ans:
public class a:ICommonImplements1,ICommonImplements2
{
public int getCommon()
{
return 1;
}
}
94. interface IWeather
95. {
96. void display();
97. }
98. public class A:IWeather
99. {
100. public void display()
101. {
102. MessageBox.Show("A");
103. }
104. }
105. public class B:A
106. {
107. }
108. public class C:B,IWeather
109. {
110. public void display()
111. {
112. MessageBox.Show("C");
113. }
114. }
115. When I instantiate C.display(), will it work?
116. interface IPrint
117. {
118. string Display();
119. }
120. interface IWrite
121. {
122. string Display();
123. }
124. class PrintDoc:IPrint,IWrite
125. {
126. //Here is implementation
127. }
how to implement the Display in the class printDoc (How to resolve the naming Conflict) A: no naming conflicts
class PrintDoc:IPrint,IWrite
{
public string Display()
{
return "s";
}
}
128. interface IList
129. {
130. int Count { get; set; }
131. }
132. interface ICounter
133. {
134. void Count(int i);
135. }
136. interface IListCounter: IList, ICounter {}
137. class C
138. {
139. void Test(IListCounter x)
140. {
141. x.Count(1); // Error
142. x.Count = 1; // Error
143. ((IList)x).Count = 1; // Ok, invokes IList.Count.set
144. ((ICounter)x).Count(1); // Ok, invokes ICounter.Count
145. }
146. }
147. Write one code example for compile time binding and one for run time binding? What is early/late binding?
An object is early bound when it is assigned to a variable declared to be of a specific object type. Early bound objects allow the compiler to allocate memory and perform other optimizations before an application executes.
' Create a variable to hold a new object.
Dim FS As FileStream
' Assign a new object to the variable.
FS = New FileStream("C:\tmp.txt", FileMode.Open)
By contrast, an object is late bound when it is assigned to a variable declared to be of type Object. Objects of this type can hold references to any object, but lack many of the advantages of early-bound objects.
Dim xlApp As Object
xlApp = CreateObject("Excel.Application")
148. Can you explain what inheritance is and an example of when you might use it?
149. How can you write a class to restrict that only one object of this class can be created (Singleton class)?
150. What are the access-specifiers available in c#?
Private, Protected, Public, Internal, Protected Internal.
151. Explain about Protected and protected internal, “internal” access-specifier?
protected - Access is limited to the containing class or types derived from the containing class.
internal - Access is limited to the current assembly.
protected internal - Access is limited to the current assembly or types derived from the containing class.