Sie sind auf Seite 1von 12

Explain what is an object?

An object is a combination of messages and data. Objects can receive and send messages
and use messages to interact with each other. The messages contain information that is to
be passed to the recipient object.
Explain about Object oriented programming?
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.
Explain about a class?
Class describes the nature of a particular thing. Structure and modularity is provided by a
Class in object oriented programming environment. Characteristics of the class should be
understandable by an ordinary non programmer and it should also convey the meaning of
the problem statement to him. Class acts lie a blue print.
Describe the principles of OOPS
Inheritance
The easiest way to e!plain something new is to start with something old. If you want to
describe what a ""schooner## is, it helps if your listeners already now what ""sailboat##
means. If you want to e!plain how a harpsichord wors, it#s best if you can assume your
audience has already looed inside a piano, or has seen a guitar played, or at least is
familiar with the idea of a ""musical instrument.##
The same is true if want to define a new ind of object$ the description is simpler if it can
start from the definition of an e!isting object.
%ith this in mind, object&oriented programming languages permit you to base a new class
definition on a class already defined. The base class is called a superclass$ the new class
is its subclass. The subclass definition specifies only how it differs from the superclass$
everything else is taen to be the same.
'othing is copied from superclass to subclass. Instead, the two classes are connected so
that the subclass inherits all the methods and instance variables of its superclass, much as
you want your listener#s understanding of ""schooner## to inherit what they already now
about sailboats. If the subclass definition were empty (if it didn#t define any instance
variables or methods of its own), the two classes would be identical (e!cept for their
names) and share the same definition. It would be lie e!plaining what a ""fiddle## is by
saying that it#s e!actly the same as a ""violin.## *owever, the reason for declaring a
subclass isn#t to generate synonyms, but to create something at least a little different from
its superclass. +ou#d want to let the fiddle play bluegrass in addition to classical music.
Explain about abstraction?
Abstraction can also be achieved through composition. It solves a comple! problem by
defining only those classes which are relevant to the problem and not involving the whole
comple! code into play.
Explain about a class in OOP?
In Object oriented programming usage of class often occurs. A class defines the
characteristics of an object and its behaviors. This defines the nature and functioning of a
specified object to which it is assigned. Code for a class should be encapsulated.
Explain the usage of encapsulation?
,ncapsulation specifies the different classes which can use the members of an object. The
main goal of encapsulation is to provide an interface to clients which decrease the
dependency on those features and parts which are liely to change in future. This
facilitates easy changes to the code and features.
Explain the different forms of Polymorphism
-ses of Inheritance
The classic e!amples of an inheritance hierarchy are borrowed from animal and plant
ta!onomies. .or e!ample, there could a class corresponding to the /inaceae (pine) family
of trees. Its subclasses could be .ir, Spruce, /ine, *emloc, Tamarac, 0ouglas.ir, and
TrueCedar, corresponding to the various genera that mae up the family.
The /ine class might have Soft/ine and *ard/ine subclasses, with %hite/ine, Sugar/ine,
and 1ristlecone/ine as subclasses of Soft/ine, and /onderosa/ine, 2ac/ine,
3onterey/ine, and 4ed/ine as subclasses of *ard/ine.
There#s rarely a reason to program a ta!onomy lie this, but the analogy is a good one.
Subclasses tend to speciali5e a superclass or adapt it to a special purpose, much as a
species speciali5es a genus.
*ere are some typical uses of inheritance6
4eusing code. If two or more classes have some things in common but also differ in some
ways, the common elements can be put in an a single class definition that the other
classes inherit. The common code is shared and need only be implemented once.
.or e!ample, .aucet, 7alve, and %ater/ipe objects, defined for the program that models
water use, all need a connection to a water source and they all should be able to record
the rate of flow. These commonalities can be encoded once, in a class that the .aucet,
7alve, and %ater/ipe classes inherit from. A .aucet can be said to be a ind of 7alve, so
perhaps the .aucet class would inherit most of what it is from 7alve, and add very little
of its own.
Setting up a protocol. A class can declare a number of methods that its subclasses are
e!pected to implement. The class might have empty versions of the methods, or it might
implement partial versions that are to be incorporated into the subclass methods. In either
case, its declarations establish a protocol that all its subclasses must follow.
%hen different classes implement similarly named methods, a program is better able to
mae use of polymorphism in its design. Setting up a protocol that subclasses must
implement helps enforce these naming conventions.
0elivering generic functionality. One implementor can define a class that contains a lot of
basic, general code to solve a problem, but doesn#t fill in all the details. Other
implementors can then create subclasses to adapt the generic class to their specific needs.
.or e!ample, the Appliance class in the program that models water use might define a
generic water&using device that subclasses would turn into specific inds of appliances.
Inheritance is thus both a way to mae someone else#s programming tas easier and a
way to separate levels of implementation.
3aing slight modifications. %hen inheritance is used to deliver generic functionality,
set up a protocol, or reuse code, a class is devised that other classes are e!pected to
inherit from. 1ut you can also use inheritance to modify classes that aren#t intended as
superclasses. Suppose, for e!ample, that there#s an object that would wor well in your
program, but you#d lie to change one or two things that it does. +ou can mae the
changes in a subclass.
/reviewing possibilities. Subclasses can also be used to factor out alternatives for testing
purposes. .or e!ample, if a class is to be encoded with a particular user interface,
alternative interfaces can be factored into subclasses during the design phase of the
project. ,ach alternative can then be demonstrated to potential users to see which they
prefer. %hen the choice is made, the selected subclass can be reintegrated into its
superclass.
Explain what a method is?
A method will affect only a particular object to which it is specified. 3ethods are verbs
meaning they define actions which a particular object will perform. It also defines various
other characteristics of a particular object.
89) 'ame the different Creational patterns in OO design:
There are three patterns of design out of which Creational patterns play an important role
the various patterns described underneath this are6 &
8) .actory pattern
;) Single ton pattern
<) /rototype pattern
=) Abstract factory pattern
9) 1uilder pattern
What Is Inheritance?
0ifferent inds of objects often have a certain amount in common with each other.
3ountain bies, road bies, and tandem bies, for e!ample, all share the characteristics
of bicycles (current speed, current pedal cadence, current gear). +et each also defines
additional features that mae them different6 tandem bicycles have two seats and two sets
of handlebars$ road bies have drop handlebars$ some mountain bies have an additional
chain ring, giving them a lower gear ratio.
Object&oriented programming allows classes to inherit commonly used state and behavior
from other classes. In this e!ample, 1icycle now becomes the superclass of
3ountain1ie, 4oad1ie, and Tandem1ie. In the 2ava programming language, each
class is allowed to have one direct superclass, and each superclass has the potential for an
unlimited number of subclasses
What Is an Interface?
objects define their interaction with the outside world through the methods that they
e!pose. 3ethods form the object#s interface with the outside world$ the buttons on the
front of your television set, for e!ample, are the interface between you and the electrical
wiring on the other side of its plastic casing. +ou press the >power> button to turn the
television on and off.
In its most common form, an interface is a group of related methods with empty bodies.
A bicycle#s behavior, if specified as an interface, might appear as follows6
interface 1icycle ?
void changeCadence(int new7alue)$
void change@ear(int new7alue)$
void speed-p(int increment)$
void apply1raes(int decrement)$
A
Explain about multiple inheritance?
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.
Explain about encapsulation?
,ncapsulation passes the message without revealing the e!act functional details of the
class. It allows only the relevant information to the user without revealing the functional
mechanism through which a particular class had functioned.
What are the problems faced by the deeloper using object oriented programming
language?
These are some of the problems faced by the developer using object oriented language
they are6 &
8) Object oriented uses design patterns which can be referred to as anything in general.
;) 4epeatable solution to a problem can cause concern and disagreements and it is one of
the major problems in software design.
B) State some of the advantages of object oriented programming:
Some of the advantages of object oriented programming are as follows6 &
8) A clear modular structure can be obtained which can be used as a prototype and it will
not reveal the mechanism behind the design. It does have a clear interface.
;) ,ase of maintenance and modification to the e!isting objects can be done with ease.
<) A good framewor is provided which facilitates in creating rich @-I applications.
Explain about instance in object oriented programming?
,very class and an object have an instance. Instance of a particular object is created at
runtime. 7alues defined for a particular object define its State. Instance of an object
e!plains the relation ship between different elements
can we create a object of !ase class?"" If we can not create a object of base class then
why we need #bstract class?
8. +es we can create object to the base class. Abstract class is nothing but a class in which
some function have definitions and some have only declarations.
;. yes, we can create a object of base class in the derived class. while Abstract classes
may contain one or more abstract methods and having no implementation in the abstract
class. if you inherit the abstract class if you have to implements all the abstract methods
of the abstract class.
What is the similarities between macro and function?
3acro wors similar to a function, but it#s e!ecution time is faster than function. Also,
macro simply substitutes the value without performing calculatons where as function
does calculations. The following e!ample describes the difference between macro and
function6
3acro6
Cdefine sD(!) !E!
if you call sD(9F9), the result will be <9 becos macro directly substitutes the value. i.e, in
this case, 9F9E9F9 G <9.
.unction6
int sD(!)
?
return !E!$
A
if you call sD(9F9) now, the result will be 8HH, because function calculates the argument
value (if it has some calculations) and passes to the operation stac. i.e, in this case
sD(9F9) will become sD(8H) before passing to return !E!.
Explain about abstraction?
Abstraction simplifies a comple! problem to a simpler problem by specifying and
modeling the class to the relevant problem scenario. It simplifies the problem by giving
the class its specific class of inheritance. Composition also helps in solving the problem
to an e!tent.
Explain about polymorphism?
/olymorphism helps a sub class to behave lie a parent class. %hen an object belonging
to different data types respond to methods which have a same name, the only condition
being that those methods should perform different function.
What is the difference between encapsulation and datahiding"explain with example
It is the mechanism that binds together code and data in manipulates, and eeps both safe
from outside interference and misuse. In short it isolates a particular code and data from
all other codes and data.
e!6
Class 1ase
?
int aG8$
/ublic void fun8?A
A
Abt data hiding,we access the data from a class in a secure way using the object.
Explain about oerriding polymorphism?
Overriding polymorphism is nown to occur when a data type can perform different
functions. .or e!ample an addition operator can perform different functions such as
addition, float addition etc. Overriding polymorphism is generally used in comple!
projects where the use of a parameter is more.
while copying the objects if you say $ a % b and asssume that &%& operator is
oerloaded then what it will call' a copy constructor or operator oerloading
function
I aGb is internally represented as I a(b). The compiler will call a copy constructor and
not the overloaded G operator. as for theoperator to be called the J*S object should have
been instantiated before the call. but in the above case it is getting instantiated in the
same call. so copy constructor will be called doing a shallow copy. a standard one will be
generated by the compiler only
Explain the Polymorphism principle
/olymorphism
This ability of different objects to respond, each in its own way, to identical messages is
called polymorphism.
/olymorphism results from the fact that every class lives in its own name space. The
names assigned within a class definition won#t conflict with names assigned anywhere
outside it. This is true both of the instance variables in an object#s data structure and of
the object#s methods6
2ust as the fields of a C structure are in a protected name space, so are an object#s instance
variables.
3ethod names are also protected. -nlie the names of C functions, method names aren#t
global symbols. The name of a method in one class can#t conflict with method names in
other classes$ two very different classes could implement identically named methods.
3ethod names are part of an object#s interface. %hen a message is sent reDuesting an
object to do something, the message names the method the object should perform.
1ecause different objects can have different methods with the same name, the meaning of
a message must be understood relative to the particular object that receives the message.
The same message sent to two different objects could invoe two different methods.
The main benefit of polymorphism is that it simplifies the programming interface. It
permits conventions to be established that can be reused in class after class. Instead of
inventing a new name for each new function you add to a program, the same names can
be reused. The programming interface can be described as a set of abstract behaviors,
Duite apart from the classes that implement them.
Define Data #bstraction?
0ata Abstraction increases the power of programming language by creating user defined
data types. 0ata Abstraction also represents the needed information in the program
without presenting the details.
Define Data encpsulation?
0ata ,ncapsulation combines data and functions into a single unit called Class. %hen
using 0ata ,ncapsulation, data is not accessed directly$ it is only accessible through the
functions present inside the class. 0ata ,ncapsulation enables the important concept of
data hiding possible.
Explain about parametric polymorphism?
/arametric polymorphism is supported by many object oriented languages and they are
very important for object oriented techniDues. In parametric polymorphism code is
written without any specification for the type of data present. *ence it can be used any
number of times.
Define Polymorphism?
/olymorphism allows routines to use variables of different types at different times. An
operator or function can be given different meanings or functions. /olymorphism refers
to a single function or multi&functioning operator performing in different ways.
Explain about ()*?
-3J or unified modeling language is regarded to implement complete specifications and
features of object oriented language. Abstract design can be implemented in object
oriented programming languages. It lacs implementation of polymorphism on message
arguments which is a OO/s feature
Define +eusability?
This term refers to the ability for multiple programmers to use the same written and
debugged e!isting class of data. This is a time saving device and adds code efficiency to
the language. Additionally, the programmer can incorporate new features to the e!isting
class, further developing the application and allowing users to achieve increased
performance. This time saving feature optimi5es code, helps in gaining secured
applications and facilitates easier maintenance on the application.
. List few features of object oriented programming.Object oriented
programming features:
Follows bottom up approach.
Emphasis is on data.
Programs are divided into objects.
Functions and data are bound together.
Communication is done through objects.
Data is hidden.
2. List features of procedure oriented programming.Procedure oriented
programming features:
Follows top down approach.
Emphasis is on procedure.
Programs are divided into functions.
Data moves around freely.
3. What are the basic concepts of OOPs?he following are the basic concepts
of OOPs:
Classes! Objects! Data abstraction and encapsulation! Polymorphism!
"nheritance! #essage Passing! and Dynamic $inding.
4. What is a class?
Class is an entity which consists of member data and member functions which
operate on the member data bound together.
5. What is an object?
Objects are instances of classes. Class is a collection of similar %ind of objects.
&hen a class is created it doesn't occupy any memory! but when instances of
class is created i.e.! when objects are created they occupy memory space.
. What is data encapsulation?
&rapping up of member data and member functions together in a class is called
data encapsulation.
!. What is data abstraction?
Data abstraction refers to the act of providing only re(uired features and hiding
all the non)essential details for usage.
". What are #$%s?
*Ds stand for abstract data types. Classes which provide data abstraction are
referred to as *Ds.
&. What is inheritance?
he process of inheriting the properties of one object by another object is called
inheritance.
'(. What is pol)morphism?
he feature of e+hibiting many forms is called polymorphism.
''. What are the steps in*ol*ed in message passing?he following are the
steps involved in message passing:
Creating classes! creating objects! and creating communication between objects.
'2. What is d)namic binding?
he feature that the associated code of a given function is not %nown till run time
is called dynamic binding.
'3. What are the ad*antages of OOP?Data hiding helps create secure
programs.
,edundant code can be avoided by using inheritance.
#ultiple instances of objects can be created.
&or% can be divided easily based on objects.
"nheritance helps to save time and cost.
Easy upgrading of systems is possible using object oriented systems.
'4. +i*e an e,ample for object based programming language.
*da is an e+ample for object based programming language.
'5. Write the features of object based programming language.
Data hiding! data encapsulation! operator overloading and automatic initiali-ation
and clear up of objects are the important features e+hibited by object based
programming languages
'. +i*e some e,amples of pure object oriented languages.
Eiffel! .ava! /imula! /malltal% are some pure object oriented languages.
2. List the areas of applications of object oriented programming?he
following are few areas of applications of object oriented programming:
C*D0C*# systems
Office automation and decision support systems
Object oriented databases
,eal time systems
/imulation and modelling.
3. What is the difference between structure in - and class in -..?
"n C structure! by default the members are public. &hereas in C11 class! by
default the members are private.
4. What are the sections in class specification?
here are basically two sections in class specification: Class declaration and
class function definition.
5. Write the s)nta, for class declaration.
/ynta+:
class
2
private:
variables3
functions3
public:
variables3
functions3
43
. What are class members?
he variables and functions used in a class are called class members.
!. What are the *isibilit) labels?
Private! public and protected are the visibility labels.
". +i*e an e,ample for class declaration.
E+.:
class area
2
int r3
public:
void get5int r63
void area5int r63
43
&. /ow does a class pro*ide data hiding?
Data hiding is provided by a class by the use of visibility label private which
allows only the member functions to access the data declared as private.
'(. What are the wa)s of defining member functions?
#ember functions can be defined in two ways! one inside the class definition and
the other outside the class definition.
''. Write the s)nta, for defining member functions inside the class./ynta+:
class
2
private:
variables3
public:
variables:
return t)pe
0
statements1
2
43
'2. Write the s)nta, for defining member functions outside the
class./ynta+:
return type :: 5arguments6
2
body3
4
'3. What does member functions represent?
#ember functions of a class represent the behaviour of a class.
'4. Write the s)nta, for ma3ing an outside function inline?#ember functions
can be made inline even though we define them outside the class by using the
%eyword inline.
/ynta+:
class
2
variables3
public:
return type 5arguments63
43
inline return type :: 5arguments6
2
body3
4
'5. What is an object?
* region of storage with associated semantics is called an object.

Das könnte Ihnen auch gefallen