





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






Object-oriented programming (OOP) is a computer science term used to characterize a programming language that began development in the 1960’s. The term ‘object-oriented programming’ was originally coined by Xerox PARC to designate a computer application that describes the methodology of using objects as the foundation for computation. By the 1980’s, OOP rose to prominence as the programming language of choice, exemplified by the success of C++. Currently, OOPs such as Java, J2EE, C++, C#, Visual Basic.NET, Python and JavaScript are popular OOP programming languages that any career- oriented Software Engineer or developer should be familiar with.
OOP is widely accepted as being far more flexible than other computer programming languages. OOPs use three basic concepts as the fundamentals for the programming language: classes, objects and methods. Additionally, Inheritance, Abstraction, Polymorphism, Event Handling and Encapsulation.
Common Questions & Answers
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 behavior.
3) What is an Object? Object is an instance of a class. It has state, behavior and identity. It is also called as an instance of a class.
4) What is an Instance? An instance has state, behavior and identity. The structure and behavior 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 focusing on the essential characteristics of an object. Abstraction is one of the fundamental elements of the object model.
7) What is meant by Encapsulation? Encapsulation is the process of compartmentalizing the elements of an abstraction that defines the structure and behavior. 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 behavior defined in another class. This is called Single Inheritance. If a class shares the structure or behavior 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 generalized superclasses.
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 behavior, typically by implementing its abstract operations.
11) What is an Interface? Interface is an outside view of a class or object which emphasizes its abstraction while hiding its structure and secrets of its behavior.
12) What is a base class? Base class is the most generalized class in a class structure. Most applications have such root classes. In Java, Object is the base class for all classes.
13) What is a subclass? Subclass is a class that inherits from one or more classes
14) What is a superclass? superclass is a class from which another class inherits.
15) What is a constructor? Constructor is an operation that creates an object and/or initializes its state.
16) 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.
17) What is meant by Binding? Binding denotes association of a name with a class.
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) Define Modularity? Modularity is the property of a system that has been decomposed into a set of cohesive and loosely coupled modules.
21) What is meant by Persistence? Persistence is the property of an object by which its existence transcends space and time.
22) What is collaboration? Collaboration is a process whereby several objects cooperate to provide some higher level behavior.
What is an Interface? An interface has no implementation; it only has the signature or in other words, just the definition of the methods without the body. What is Polymorphism? Mean by more than one form. Ability to provide different implementation based on different number/type of parameters. What is Pure-Polymorphism? When a method is declared as abstract/virtual method in a base class and which is overridden in a base class. If we create a variable of a type of a base class and assign an object of a derived class to it, it will be decided at a run time, which implementation of a method is to be called. This is known as Pure- Polymorphism or Late-Binding. What is a Constructor? A special function Always called whenever an instance of the class is created.
class Test { int a,b; Test() { a=9; b=8; } };
Here Test() is the constructor of Class Test.
What is copy constructor? Constructor which initializes it's object member variables ( by shallow copying) with another object of the same class. If you don't implement one in your class then compiler implements one for you. for example: Test t1(10); // calling Test constructor
Test t2(t1); // calling Test copy constructor Test t2 = t1;// calling Test copy constructor Copy constructors are called in following cases:
What is default Constructor? Constructor with no arguments or all the arguments has default values. In Above Question Test() is a default constructor What is a Destructor? A special method called by GC. just before object is being reclaimed by GC. How a base class method is hidden? Hiding a base class method by declaring a method in derived class with keyword new. This will override the base class method and old method will be suppressed. What Command is used to implement properties in C#? get & set access modifiers are used to implement properties in c#. What is method overloading? Method overloading is having methods with same name but carrying different signature, this is useful when you want a method to behave differently depending upon a data passed to it. Can constructors have parameters? Yes, constructors can have parameters. so we can overload it. What are Static Assembly and Dynamic Assembly? Static assemblies can include .NET Framework types (interfaces and classes) as well as resources for the assembly (bitmaps, JPEG files, resource files, and so forth). Static assemblies are stored on disk. Dynamic assemblies run directly from memory and are not saved to disk before execution. Describe the functionality of an assembly. It is the smallest unit that has version control. All types and resources in the same assembly are versioned as a unit and support side by side execution. Assemblies contain the metadata and other identities which allow the common language runtime to execute. They are the boundaries providing the type check. They the unit where security permissions are requested and granted. What is serialization? Serialization is the process of converting an object into a stream of bytes. De-serialization is the opposite process of creating an object from a stream of bytes. Serialization/De-serialization is mostly used to transport objects (e.g. during remoting), or to persist objects (e.g. to a file or database). There are two separate mechanisms provided by the .NET class library for serialization - XmlSerializer and
What is a scope resolution operator? A scope resolution operator (::), can be used to define the member functions of a class outside the class. What do you mean by pure virtual functions? A pure virtual member function is a member function that the base class forces derived classes to provide. Normally these member functions have no implementation. Pure virtual functions are equated to zero. class Shape { public: virtual void draw() = 0; };
What is the difference between declaration and definition? The declaration tells the compiler that at some later point we plan to present the definition of this declaration. E.g.: void stars () //function declaration The definition contains the actual implementation. E.g.: void stars () { for(int j=10; j > =0; j--) //function body cout << *; cout << endl; } What are the advantages of inheritance? It permits code reusability. Reusability saves time in program development. It encourages the reuse of proven and debugged high-quality software, thus reducing problem after a system becomes functional. Association Association is a relationship where all object have their own lifecycle and there is no owner. Let’s take an example of Teacher and Student. Multiple students can associate with single teacher and single student can associate with multiple teachers but there is no ownership between the objects and both have their own lifecycle. Both can create and delete independently. Aggregation Aggregation is a specialize form of Association where all object have their own lifecycle but there is ownership and child object can not belongs to another parent object. Let’s take an example of Department and teacher. A single teacher can not belongs to multiple departments, but if we delete the department teacher object will not destroy. We can think about “has-a” relationship.
Composition Composition is again specialize form of Aggregation and we can call this as a “death” relationship. It is a strong type of Aggregation. Child object dose not have their lifecycle and if parent object deletes all child object will also be deleted. Let’s take again an example of relationship between House and rooms. House can contain multiple rooms there is no independent life of room and any room can not belongs to two different house if we delete the house room will automatically delete. Let’s take another example relationship between Questions and options. Single questions can have multiple options and option can not belong to multiple questions. If we delete questions options will automatically delete. How to Implement (Code Example) Class Circle { Point point; }; Class Point { int x; int y; }; Here Circle is composed of Point.... you can't make a circle without point (Strong dependency) Distinguish between the terms fatal error and non–fatal error. Why might you prefer to experience a fatal error rather than a non–fatal error? A fatal error causes a program to terminate prematurely. A nonfatal error occurs when the logic of the program is incorrect, and the program does not work properly. A fatal error is preferred for debugging purposes. A fatal error immediately lets you know there is a problem with the program, whereas a nonfatal error can be subtle and possibly go undetected. What are virtual functions? Describe a circumstance in which virtual functions would be appropriate Virtual functions are functions with the same function prototype that are defined throughout a class hierarchy. At least the base class occurrence of the function is preceded by the keyword virtual. Virtual functions are used to enable generic processing of an entire class hierarchy of objects through a base class pointer. For example, in a shape hierarchy, all shapes can be drawn. If all shapes are derived from a base class Shape which contains a virtual draw function, then generic processing of the hierarchy can be performed by calling every shape’s draw generically through a base class Shape pointer. Given that constructors cannot be virtual, describe a scheme for how you might achieve a similar effect Create a virtual function called initialize that the constructor invokes.