File - BE Comps.

advertisement
OOPS Questions
1: What is meant by Object Oriented Programming?
Answer:
Object Oriented Programming is a programming method 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?
Answer:
Class is a template for a set of objects that share a common structure and a common behavior. It is
an expanded concept of a data structure: instead of holding only data, it can hold both data and
functions.
Classes are generally declared using the keyword class, with the following format:
class class_name {
access_specifier_1:
member1;
access_specifier_2:
member2;
....
} object_names;
3: What is an Object?
Answer:
Object is an instance of a Class. It has state, behavior and identity. In terms of variables, a Class
would be the type, and an Object would be the variable.
4: What is an Instance?
Answer:
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 concepts of OOPS?
Answer:
Abstraction, Encapsulation, Inheritance and Polymorphism are the core concepts of OOPS.
6: What is meant by Abstraction?
Answer:
Abstraction defines the essential characteristics of an object that distinguishes itself from all other
kinds of objects. Abstraction provides crisply-defined conceptual boundaries relative to the
perspective of the viewer. It’s 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?
Answer:
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. It is the process of combining data and functions into a single unit called class.
Using the method of encapsulation, the programmer cannot directly access the data. Data is only
accessible through the functions present inside the class.
8: What is meant by Inheritance?
Answer:
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 super classes.
9: What is meant by Polymorphism?
Answer:
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. It is a powerful feature of the object oriented programming language. A single operator
behaves differently in different contexts such as integer, float or strings referring the concept of
Polymorphism. It refers to the ability to call different functions by using only one type of function call.
10: What is an Abstract Class?
Answer:
An Abstract Class or Abstract Base Class (ABC), is a class that cannot be instantiated. Such a class
is only meaningful if the language supports inheritance. An Abstract Class is designed only as a
parent class from which child classes may be derived. Abstract classes are often used to represent
abstract concepts or entities. The incomplete features of the abstract class are then shared by a
group of subclasses which add different variations of the missing pieces.
11: What is an Interface?
Answer:
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?
Answer:
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?
Answer:
Subclass is a Class that inherits from one or more classes.
14: What is a Super Class?
Answer:
Super Class is a Class from which other classes are derived. The classes that are derived from a
superclass are known as child classes, derived classes, or subclasses.The superclass mechanism is
extensively used in object oriented programming due to the reusability that can be achieved:
common features are encapsulated in modular objects.
15: What is a Constructor?
Answer:
Constructor is an operation that creates an object and/or initializes its state. A Constructor contains
all the initialisation code and is automatically called everytime an object is created. A constructor has
the same name as the class so that it can be easily distinguished from other functions.
16: What is a Destructor?
Answer:
Destructor is an operation that frees the state of an object and/or destroys the object itself. The
destructor fulfills the opposite functionality of constructor. It is automatically called when an object is
destroyed, either because its scope of existence has finished (for example, if it was defined as a
local object within a function and the function ends) or because it is an object dynamically assigned
and it is released using the operator delete. The destructor must have the same name as the class,
but preceded with a tilde sign (~) and it must also return no value. The use of destructors is
especially suitable when an object assigns dynamic memory during its lifetime and at the moment of
being destroyed we want to release the memory that the object was allocated. In Java, there is no
concept of destructors. It is taken care by the JVM.
17: What is meant by Binding?
Answer:
Binding denotes association of a name with a Class.
18: What is meant by Early Binding?
Answer:
Static Binding is a binding in which the Class association is made or in other words, all code is
bound during compile time. This is also called as Early binding.
19: What is meant by Late Binding?
Answer:
Late Binding is a binding in which the Class association is not made until the object is created at
execution time. In other words, binding that takes place at run-time. It is also called as Dynamic
binding.
20: Define Modularity?
Answer:
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?
Answer:
Persistence is the property of an object by which its existence transcends space and time.
22: What is Collaboration?
Answer:
Collaboration is a process whereby several objects cooperate to provide some higher level
behaviour.
23: In Java, how to make an object completely Encapsulated?
Answer:
To make an object completely Encapsulated, all the instance variables should be declared as private
and public. getter and setter methods should be provided for accessing the instance variables.
24: How is Polymorphism achieved in Java?
Answer:
Inheritance, Overloading and Overriding are used to achieve Polymorphism in Java.
25: Explain the rationale behind Object Oriented concepts?
Answer:
Object Oriented Concepts form the base of all modern programming languages. Understanding the
basic concepts of object-orientation helps a developer to use various modern day programming
languages, more effectively.
26: Explain about Object Oriented Programming?
Answer:
Object Oriented Programming is one of the most popular methodologies in software development. It
offers a powerful model for creating computer programs. It speeds the program development
process, improves maintenance and enhances reusability of programs.
29: Explain about Instance in Object Oriented Programming?
Answer:
Every Class and an object have an Instance. Instance of a particular object is created at runtime.
Values defined for a particular object define its State. Instance of an object explains the relationship
between different elements.
30: Explain Multiple Inheritance?
Answer:
Inheritance involves inheriting characteristics from its parents also they can have their own
characteristics. In Multiple Inheritance a Class can have characteristics from multiple parents or
classes. A sub Class can have characteristics from multiple parents and still can have its own
characteristics.
32: Explain about Overriding Polymorphism?
Answer:
Overriding Polymorphism is known to occur when a data type can perform different functions. For
example an addition operator can perform different functions such as addition, float addition etc.
Overriding polymorphism is generally used in complex projects where the use of a parameter is
more.
33: Explain about Object Oriented Databases?
Answer:
Object Oriented Databases are also popular as Relational Database Management Systems(RDMS).
Object oriented databases systems use specific structure through which they extract data and they
combine the data for a specific output. These DBMS use object oriented languages to make the
process easier.
34: Explain about Parametric Polymorphism?
Answer:
In Parametric Polymorphism code is written without any specification for the type of data present.
Hence it can be used any number of times. Parametric Polymorphism is supported by many object
oriented languages and they are very important for object oriented techniques.
35: Which are the languages which support OOP?
Answer:
There are several programming languages which are implementing OOP because of its close
proximity to solve real life problems. Languages such as Python, Ruby, Ruby on rails, Perl, PHP,
ColdFusion, etc use OOP. Still many languages prefer to use DOM based languages due to the
ease in coding.
36: What are Concrete Classes?
Answer:
A concrete class is a class that can be instantiated and whose all methods have body.
37: What does a keyword PUBLIC means?
Answer:
As the name specifies, it can be accessed from anywhere. If a member of a class is defined as
public then it can be accessed anywhere in the class as well as outside the class. This means that
objects can access and modify public fields, properties, methods.
45: Explain about the relationship between Object Oriented Programming and Databases?
Answer:
Object Oriented Programming and Relational Database Programming are almost similar in software
engineering. RDBMS will not store objects directly and that’s where object oriented programming
comes into play. Object relational mapping is one such solution.
46: Discuss the Advantages of the concept of Polymorphism?
Answer:
a) Once an application is written using the concept of polymorphism, it can easily be
extended, providing new objects that conform to the original interface.
b) It is unnecessary to recompile original programs by adding new types. Only re-linking is
necessary to exhibit the new changes along with the old application. This is the greatest
achievement of object-oriented programming.
c) In programming language, there has always been a need for adding and customizing. By
utilizing the concept of polymorphism, time and work effort is reduced in addition to making
future maintenance easier.
d) Polymorphism helps in reusability of code.
e) Polymorphism provides easier maintenance of applications.
f) Polymorphism helps in achieving robustness in applications.
47: What is the difference between Data Hiding and Encapsulation?
Answer:
Data Hiding is a concept of making all the data (fields) private i.e. not accessible from the other
objects, classes, APIs in the system. Only the class/object/API knows about the data and how to
operate them. Encapsulation is the combination of abstraction and data hiding, means we are
wrapping data and code associated with that data.
Download