CS6456 - OBJECT ORIENTED PROGRAMMING HAND MATERIALStaff
Incharge: S.Ashok Kumar AP/CSEPart-A -2 marks1. Differentiate
between class and objectClass Object
A class has a unique nameSeveral objects with different names
can be created for same class
Scope of the class is persistent throughout the program.Objects
can be created and destroyed as per requirements.
2. Differentiate between Data encapsulation and Data
abstractionData encapsulationData abstraction
It is a binding of data and the functions together in a single
entity called class.
Data abstraction helps in representing only the essential
features by hiding all the implementation details.
Data encapsulation is achieved by inheritanceData abstraction is
represented by using abstract class
3. What is an abstract class? Abstract class is the class that
does not specify the implementation details, but specifies what are
the operations to be done. We cannot create object for an abstract
class. Example: Vehicle is an abstract class.4. What is ADT? ADT
stands for Abstract Data Type. It does not specify the
implementation details, but specifies what are the operations to be
done.5. What is the use of ADT? The user need not have to
understand the implementation details. Finding of bugs is easy.6.
What is Object Oriented Programming? Object Oriented Programming is
a collection of objects.7. What are friend functions? Friend
function is not a member function of the class but it can access
the private and protected members of a class.
8. What is polymorphism? Polymorphism means many forms.
Polymorphism is the ability of object to exhibit more than one
forms 9. List the operators that cannot be overloaded? Scope
resolution operator ( :: ) Size of operator Conditional operator(
?: ) Dot operator ( . )10. What is a container? Container is a
collection of objects of different type. These objects store the
data.11.What are called iterators? It is also used to traverse the
contents of container. Iterators are basically objects and
sometimes they can be pointers. It is used to specify the position
in the container.12. What is STL? STL is Standard Template Library.
STL is a collection of C++ classes and functions13. Define
exception. Give example. Exception is an run time error or some
abnormal situations which occurs in a program. Exception can be
handled by using exception handler.Example: Division by zero 14.
What are virtual functions? How are virtual functions declared in
C++? A virtual function is a member function that is declared
within a base class and redefined in the derived class. Virtual
functions are declared using the keyword virtual.15. Define pure
virtual function and mention its usage. Pure virtual function does
nothingSyntax for declaring pure virtual functionvirtual void
functionname( ) =0;Usage: It is used in the abstract class 16. What
are virtual base class? In order to overcome the ambiguity problem
which occurs in multiple inheritance, the base class is made
virtual.17. What is the difference between function template and
template function?Function templateTemplate function
In function template, single function template is written and
that can handle elements of different data type.Template function
is invoking the function with different parameters
Exampletemplatevoid add(T a, T
b){.}Example:add(10,20);add(10.5,12.7);
18. What is JVM? JVM is Java Virtual Machine. It is a set of
software and program components. Java is platform independent due
to JVM.19. What is a byte code? Mention its advantage. The class
file created while compiling java code is called byte code. Byte
code is used to make a java as a platform independent language.20.
Why is java language called as robust? Java is robust because it
can be used on multiple platforms. Java provides a good mechanism
for error checking.21. How do we allocate an array dynamically in
Java? We allocate memory for the array dynamically using new
operator.Example:int a[ ]=new int[10]; //Dynamically allocates a
memory for an array a.22. How is keyword super is used in Java?
Keyword super is used to call super class constructor and super
class functions.23. Java does not support multiple inheritance?
Why?
Class BVoid display( )Class AVoid display( )
Class CClass As void display( )Class Bs void display( )
When Class C is inherited from class A and class B, Class As
void display( ) and Class Bs void display( ) will becomes members
of class C. When display( ) function is called, compiler doesnt
know which display( ) to call and hence AMBIGUITY problem arise.24.
What are packages? Package is a mechanism in which variety of
classes, functions and interfaces are grouped together.25. What is
API package? API package is a collection of packages which includes
the important classes and interfaces which are used by the
programmer while developing java applications. Some of the Java API
packages are java.io, java.util, java.lang etc. 26. Define
interface. State its use. Interface is similar to the class which
contains data members and the functions. But the functions are not
defined in interfaceUse: It is used to hide the implementation
details from the rest of the code. 27. What is a thread? How does
it differ from a process? Thread is a light weight process which
shares a same address space and same heavy weight process. (i.e)
Multiple threads executes in a process
simultaneously.ThreadProcess
Thread is a light weight processProcess is a heavy weight
process
Several threads share a same address space and share the same
heavy weight processProcesses requires separate address space
Switching from one thread is another thread is of low
costSwitching from one process to another is costly
28. What are the two ways of creating java threads? Java threads
can be created by using Thread class and Runnable interface29. What
is multithreading? Multiple threads executes in a process which
performs multiple tasks simultaneously.30. What is a stream? Stream
is a channel on which a data flow from sender to receiver.31.What
are the types of streams? Byte Stream =>Read and write one byte
at a time. Character Stream=> Read and write one character at a
time.
1. Explain in detail about the various object oriented concepts.
(OR) Explain the features of Object Oriented Programming. (OR)
Explain the various important paradigm of Object Oriented
Programming with example1.Class 2.Objects 3.Data encapsulation
4.Inheritance 5.Polymorphism 6.Dynamic binding 7.Data abstraction1.
class A class is a collection of objects of same type.Example:class
student{int rollno;public:void get( );void display( );};2. objects
An Object is a instance of a class. Example: student s; where
student is the class name and s is the object.3. Data encapsulation
It is a binding of data and the functions together in a single
entity called class.
Data Encapsulation4. Inheritance New class is derived from the
old class. It provides REUSABILITY.Types of Inheritance: Single
level inheritance, multiple inheritance, multilevel inheritance,
hierarchical inheritance, hybrid inheritance.5. Polymorphism The
ability to take more than one form is called polymorphismTypes:1.
Compile time polymorphism - Function overloading, Operator
OverloadingFunction overloading: Same function name is used with
different arguments.Operator overloading: Same operator is used to
perform different function.2. Run time polymorphism Virtual
Function6. Dynamic binding Dynamic binding is the process of
matching the function call with the correct definition at the run
time.7. Data abstraction Data abstraction helps in representing
only the essential features by hiding all the implementation
details. Example: class
2.Explain constructor and destructor in detail with necessary
examples.ConstructorDestructor
Definition Constructor is automatically called when the object
of the class is created. Constructor name is same as the class
name.Definition The destructor is called when the object is
destroyed. The destructor name is same as the class name but
preceded with tilde(~) symbol.
Types of constructor: Default Constructor=> It is called
whenever the object of the class is created. It set the initial
value for the data members of class.Parameterized constructor=>
It is called whenever values are passed to the object. It is used
to set the new values to the data members of class. Copy
constructor=> It is called when a object is passed as argument
to another object It takes the reference to an object of same class
as argument.Overloaded Constructor => Constructor with different
arguments Dynamic constructor=> Dynamic constructor allocates
memory for objects using the operator new.Example
program#include#includeclass image{private:int
height,width;public:image( ){height=0;width=0;} Default
Constructor
image(int x,int y){height=x;width=y;}
Parameterized Constructor
image(image &obj){height=obj.height;width=obj.width;}
Copy Constructor
Overloaded Constructor
void display( ){cout