Anna University
CS2311 OBJECT ORIENTED PROGRAMMING
Department of EEE
Semester : 5
Subject Name : OBJECT ORIENTED PROGRAMMING
Two Marks with Answers
UNIT-I
1. What are the Concepts of OOPs
- Objects
- Classes
- Data Abstraction
- Data Encapusulation
- Inheritance
- Polymorphism
- Message Passing
- Dynamic Binding
2. Differentiate Procedure Oriented Programming(POP) and Object Oriented
Programming(OOP)
POP
1) Emphasis on non-real itrem
2) Programs are divided into functions
3) Data are sharable
4) Structured Programming
5) Top-Down Approach
OOP
1) Emphasis on real item
2) Programs are divided into Objects
3) Data are not sharable
4) Object Oriented Programming
5) Bottam-Up Arpproach
3. Define Tokens
Smallest individual unit in a program. C++ tokens are Keywords, Identifiers, Constants,
Strings, Operators
4. What are the Data Types in C++
Built-in Data types
User Defined Data types
Derived Data Types
5. Write the Block Structure of C++
Include Files
Class Declaration
Member Function Defintions
Main Function Program
6. What are the Operators in C++
- Scope Resolution Operator : :
- Pointer-to-Pointer Member Declarator : :*
- Pointer-to-Pointer Member Operator ->*
- Pointer-to-Pointer Member Operator .*
- Delete-Memory Release Operator
- Endl-Line feed operator
- New-Memory allocation operator
- Setw-Memory width operator
7. What is expression? What are the expressions in C++?
- Constant Expressions
- Integral Expressions
- Float Expressions
- Pointer Expressions
- Relational Expressions
- Logical Expressions
- Bitwise Expressions
8. What is meant by Data Hiding?
Data are hidden inside a class, that can not be accessed by any function outside the
class. It is achived by declaring the data part as private.
9 . What is Polymorphism? What the are the types of Polymorphism.
Polymorphism mean many forms. Types of Polymorphism are
ü Runtime Polymorphism
ü Compile time Polymorphism
10. Differentiate Constructor and Destructors.
Constructors cannot be virtual. Destructors can be Virtual. Construtors must be
declared in public. Destructors must be declared in public. Constructors has arguments.
Destructors has no arguments.
11. What is function? What are the types of Function in C++?
- Functions with Arguments and No Return Values
- Functions with No Arguments and No Return Values
- Functions with Arguments and Return Values
12. What are the Features of Inline Function?
- Run Faster
- Function Call & Return is Eliminated
- Improves Performance
13. What are the Components of Functions?
- Function Declaration
- Function Parameters
- Function Definition
- Return Statement
- Function Call
14. What is Default Arguments
A function with same name, Different arguments is known as Default Arguments
15. What is Function Overloading?
Overloading refers to the use of same thing for different purpose. i.e., Same
function name performs variety of different tasks. Also known as Function polymorphism.
16.What are the parameter passing in C++.
ü Pass by value
ü Pass by Address
ü Pass by reference
17. Define Class?
A class encloses both data and functions that operate on the data, into a single unit.
18. Define Object Based Language.
Object Based Language=Encapsulation + Object Identity
Object Oriented Language= Object Based Features + Inheritance + Polymorphism
19. What are the Access Specifiers in C++.
- Public
- Private
- Protected
20. What is Static Variables?
Defined with in the function, static variable initialized only once. Contents of the
variables retained throughout the program.
21. Static Member Functions?
Static Function can have accessed by only static members declared in the same
class. Static member function called using the name of class instead of its objects.
22. Define Constructor.
It is a member function having name of its class. It is executed automatically when
object is created. It is used to initialize object and allocate the necessary memory.
23. Define Destructor.
It is a member function having the char ~ followed by name of its class. It is executed
automatically when object goes out of scope. A class must have only one constructor.
24. Define Constructor Overloading.
A class can have multiple constructors. This is called constructor overloading.
25. What is order of Constructor and Destructor
When more than one object is created, they are destroyed in the reverse
Chronological order. Object created must recently is the first one to be destroyed.
26. What is meant by Parameterized constructors.
Constructor that can take arguments are called parameterized constructor.
27. What is meant by Copy Constructors?
It is used to declare and initialize an object from another object
For example
Integer i2 (i1)
Define I2 and at the same time initialize it to the values of i1.
UNIT - II
1. Define Friend Function.
Private members cannot be accessed from outside the class. To make an outside
function “ Friendly” to a class, declare this function as a friend of the class.
2. What is meant by Friend Class?
We can also declare all the member function of one class the friend of another class. In
such cases , the class is called a friend class.
3. What are the Special Characteristics of Friend Function?
- The function definition does not use friend keyword
- It is not in the scope of the class which is declared as friend
- It can be called like normal function without the help of any object
- Friend function acts as a Bridge between 2 classes
4. Define Operator Overloading?
To define an additional task to an operator. Mechanism of giving such special
meanings to an operator is known as Operator Overloading.
5. What are the Operators of C++ that cannot be overloaded?
- . , .* - class member access operator
- :: - Scope Resolution Operaotr
- Sizeof-Size of Operator
- ?:- Conditional Operator
6. Define Inheritance.
Creating new class from old class. (or) Deriving a new class from old class.
7. What are types of Inheritance?
- Single Inheritance
- Multiple Inheritance
- Multilevel Inheritance
- Hybrid Inheritance
- Hierarchical Inheritance
8. What are visibility modes of Inheritance?
- Private
- Public
- Protected
Note: Private members are not inheritable, inaccessible to the objects of derived class.
9. How can you define member functions in c++?
Defined inside the classDefined outside the class
10. What is meant by Abstract Class?
It is the one that is not used to create objects. That is, abstract class is designed only
to act as a base class.
11. What is meant by intermediate base class?
In multilevel inheritance, first level derived class is known as intermediate base
class.
12. What is meant by Automatic Initialization of objects.
C++ provides a special member function called the constructor which enables an
object to initialize itself when it is created.
13 . What is meant by Hybrid Inheritance?
2 or more types of inheritance used to derive a class. 2 or set of class acts as a base
class, from which we can derive a new class.
14. What is meant by Multipath Inheritance?
Consists of multiple, multilevel and hierarchical inheritance.
15. Define Virtual Base Class.
Duplication of inherited members due to multiple paths can be avoided by making
the common base class as virtual base class.
16. Define Virtual Function?
It is used to invoke exact version of the member function. Virtual functions should
be defined in the public section of a class
17. How can you access the virtual functions.
Virtual functions have to be accessed through a pointer to the base class. It is not
accessible directly.
What are the types of type conversion?
- conversion from basic type to class type
- conversion from class type to basic type
- conversion from one class type to another
18. What is operator overloading?
The mechanism of giving such special meanings to an operator is known as operator
overloading. or In c++ you can give special meanings to operators when they are
used with user defined classes. This is called operator overloading.
19. Why is it necessary to overload an operator?
To define a new relation task to an operator, we must specify what it means in
relation to the class to which the operator is applied. This is done with the help of a special
function called operator function.
Or
It allows the developer to program using notation closer to the target domain and
allow user types to look like types built into the language.
Or
The ability to tell the compiler how to perform a certain operation when its
corresponding operator is used on one or more variables.
20. What is a conversion function? How it is created? Explain its syntax
The type of data to the right of an assignment operator is automatically converted to
the type of the variable on the left. For e.g., the statements
int m;
float x=3.14;
m=x;
Convert x to an integer before its value is assigned t0 m. thus the fractional part is
truncated.
21. When is a friend function compulsory? Give an eg.
A friend function is necessary when you an function outside the class. And to access
the private members of the class or the member function and also friend class can
directly access the private and protected data.
1. What is containership?
A class can contain objects of other classes. It is known as containership.
2. What is meant by pure virtual function?
A virtual function, equated to zero is called a pure virtual function.
3. What are rules for virtual function.
- The virtual functions must be members of some class
- They can not be static members
- They are accessed by object pointers
- Virtual function can be friend of another class.
4. What is meant by Streams?
A stream is a sequence of bytes and serves as a source or destination for an I/O data.
There 2 types of streams
- Input stream
- Output stream
5. Differentiate input and output stream.
Input stream provides data to the program
Output stream receives output from the program
6. How can you access private members?
There are mechanism to access even private data using friend function, pointer to
members etc from outside the class.
7. What is meant by empty class?
Empty class consists of no member functions and no member variables
For example
Class abcd
{
----
}
8. What are the benefits of inheritance?
- Code Reuse
- Ease of code maintainence
- Increase reliability
- Improved performance
- Less maintenance
- Easy to extension
9. What are the Unformatted I/O Operations?
- Cin
- Cout
- Get()
- Put()
10. Differentiate Get() and Put() member functions.
Get() member functions used to read single character from keyboard and Put()
member functions used to write single character to screen.
11. Differentiate Getline() and Putline() member functions.
Getline() Function reads strings and ends with newline character
Putline() function displays strings on the screen.
12. What is meant by pure abstract class?
A class containing pure virtual function is called pure abstract class .
13. What is meant by Concreate Class.
A class containing no pure virtual function is known as concreate class.
14. What are the ios format functions.?
- Width()
- Precison()
- Fill()
- Setf
- Unsef
15. What is meant by manipulators
The header file iomanip provides a set of functions called manipulators which can
be used to manipulate the output formats. They provide same features as that of the ios
member functions and flags.
16. What are manipulators in C++?
- Setw(w)
- Setprecison(d)
- Setfill(c)
- Setiosflags(f)
- Resetiosflags(f)
- Endl
17. Define file.
File is collection of Records. Record is a collection of different data.
18. Differentiate file input stream and file output stream?
I/P Stream extracts data from file
O/P Stream inserts data to to file
19. What are operations on file?
- Name the file on the disk
- Open the file
- Process the file(Read/Write)
- Check for errors while processing
- Close the file
20. What are the file stream class?
- Filebuf
- Fstreambase
- Ifstream
- Ofstream
- Fstream
21. What is meant by Static binding.
The Addresses of the functions are determined at runtime rather than compile time.
Also known as late binding.
22. What is meant by Dynamic binding?
Opposite to Static binding. The functions are bound to the code to be executed at
compile time. Also known as early binding.
23. What is meant by Reusability?
Supported by OOPs. This allows reuse of existing classes without redefinition.
That is reusing of existing classes .
24. What is meant by instance of classes?
An instance of a class is an object whose type is class.
25. What is STL?
A collection of generic classes and functions is called the Standard Template
Library. STL components are part of C++ standard Library.
26. What are three components of STL
The STL components are containers, algorithms and iterators.
27. Define containers.
Containers are objects that hold data of same type. Containers are divided into three
major categories: sequential, associative and derived.
28. What is iterators? What is its characteristic?
An iterator is an object (like a pointer) that points to an element in a container. We
can use iterators to move through the contents of containers. Iterators connect algorithms
with containers and play a key role in the manipulation of data stored in the containers.
29. What are the best situations for the use of the associative containers
Associate containers are designed to support direct access to elements using keys
they are not sequential. Containers are best suited for fast searching, deletion and insertion
of data in a structure called tree.
30. Compare the performance characteristics of the 3 containers.
Container Random
access
Insertion or deletion
in the middle
Inserton or deletion at the
ends
Vector Fast Slow Fast at Back
List Slow Fast Fast at front
Deque Fast Slow Fast at both the ends
UNIT - IV
1. What is meant by Java?
Object Oriented Multithreaded High Level Programming Language developed by
sun Microsystems in 1991.
2. What is meant by Platform?
Platform is the hardware or system software environment in which your program
runs. Most platforms are described as a combination of hardware and operating system.
3. Java is platform independent language. Justify.
Platform is the hardware or system software environment in which your program
runs. Moreover java language run by any operating system, thats why java is called
platform independent languages.
4. What is meant by Java Application?
An Application is a program that runs on your computer, under the operating system
of that system
5. What is meant by Java Applet?
An Applet is an application designed to be transmitted over the internet and
executed by a Java-Compatible web browser.
6. Define JDK.
JDK(Java Development Kit). JDK is a software package from Sun Microsystems.
Latest version of JDK is 1.5. This software package contains tools.
7. What are the JDK Tools
- Javac- Java Compiler
- Java –Java interpreter
- Jdb – Java Debugger
- Javap- Java Disassembler
- Javadoc- Java Documentation
- Javah - Java Header file Generator
- The Appletviewer
8. What are features of java
- Simple
- Object Oriented
- Distributed
- Interpreted
- Robust
- Secure
- Architecture-Neutral
- Portable
- High Performance
- Multithreaded
- Dynamic Language
9. What are features does not supported by java?
- Goto statement
- Multiple inheritance
- Operator overloading
- Structures and Unions allowed
- Pointers
10. What are features supported by java
- Automatic memory management
- Multithreaded programs
11. Define Java Character Set.
- Alphabets
- Digits
- Special characters
Java uses Unicode character set.
12. What is meant by Java Class Defintion?
A java program contains 2 parts. They are
A class definition that encloses the entire program
A main() method that contains the body.
Every java program should contain atleast one class.
13. What is meant by bytecode in java?
Java compiler after compiling the program creates a new file referred as the class
file, which contains a special code referred as the bytecode. It is similar to machine
language, but unlike machine language, java byte code is exactly the same on every
platform.
14. Define JVM.
It is an abstract computing machine, having an instruction and memory, which is
used to implement the java program language. The JVM is responsible for cross-platform
portability of java.
15. Define API.
Java API are libraries of compiled code that you can use in your programs. They
let you add readymade and customizable functionality to save your programming time.
16. Define Garbage Collection in Java?
Garbage Collection also referred as automatic memory management. Periodically
frees the memory used by objects that are no longer needed. The garbage collector in java
scans dynamic memory areas for objects and marks those that are referenced. After all
possible paths to objects are investigated the unreferenced objects are freed.
17. How multiple inheritance is achieved in java?
Java does not support multiple inheritance. It is achieved by the use interface.
18. State the use of super keyword in java
The super keyword is used to access a member of an immediate base class, from a
derived class.
19. Mention the various access levels supported in java
- Public
- Protected
- Private
20. Define method overloading.
Java enables 2 or more methods with same name but with different signatures. The
signature includes the number of type, and sequence of the arguments passed to a method.
The capability to overload a method is referred to as overloading methods.
UNIT – V
1. Define Method Overriding.
When you have 2 methods with same name and same arguments list, one present in
the base class and another present in the sub class. When you access the method in the
base class using the object of the derived class, the method in the derived class will be
called instead of the method in the base class. The derived class method has overridden the
base class method.
2. Write about Access Control in Java?
- Public - Accessible to all the classes
- Private - Accessible to the class in which it is defined
- Protected - Accessible to within the class, by all the classes derived from the class
- Package - Default level of Access in java
3. What is use of Final keyword in java?
The Final keyword is similar to the keyword “Const” in C/C++. It is used several
different circumstances as a modifier meaning you can not reassign the same in some sense
4. List the Classes that represent strings in java
- String
- StingBuffer
5. What is package?
Package is a collection of related classes and interfaces. It is also defined as
“putting classes together”
6. What are the package of Java?
- Java API Packages
- User Defined Packages
7. Write about API Packages?
Java API provides a large number of classes grouped into different packages
according to functionality.
- Language Package(java.lang)
- Utilities Package(java.util)
- I/O Package(java.io)
- Networking Package(java.net)
- Applet Package(java.applet)
- AWT Package(java.awt)
8.Java does not support multiple inheritance. Why?
Classes in java cannot have more than one superclass.
For example
Class A extends B extends C
{
---
---
}
is not permitted in java.
9. What is meant by Nested Class?
A nested class is a class that is a member of another class.
10. What is meant by inner class?
Inner class is a class whose body is defined inside of another class. That is class
Contains another class.
11. What is meant by Wrapper Classes?
Corresponding to all the primitive data types java defines a set of classes referred
as wrapper classes, which serves as class versions of the fundamental data types and named
similar to the data types.
12. Define “ Instance of Operator “ in java?
The instance of operator is a keyword, which is used to find out whether the object
belongs to which class instance or not. Note that the instance of operator will cause a
compile time error if it is used to check a class when there is no inheritance.
13. Define Interface.
An Interface is basically a kind of class. Like classes, interfaces contain methods
and variables with difference. That is interface do not specify any code to implement these
methods
14. What is meant by Exception?
An Exception is an condition that is caused by a runtime error in the program. An
error may produce an incorrect output or may terminate the execution of the program.
15. Define Sub classing.
Sub classing is the creation of new class that inherits from an existing class in the
class hierarchy.
16. Mention some of the important classes present in java.net package.
- The inetaddress class
- URL class
- Socket Class
- The contenthandler class
17. What is the Significance of class path.
Java interpreter uses an environment variable classpath, to determine the path to
look for user defined classes.
18. Define Multithreading?
Multitasking means executing several programs at a time, in system terminology, it
is called multithreading. Thread is single line of execution with in the program.
19. What is life cycle of thread?
- New born state
- Runnable state
- Running state
- Blocked state
- Dead state
20. Define Synchronization.
One thread try to read a record from a file while another is still writing to the same
file. Depending on the situation, we may get strange results. To overcome this problem
using a technique known as synchronization.
21. What is meant by Deadlock?
Deadlock occurs when 2 or more threads are waiting for resources that they can’t
get.
22. Derived class is usually larger than the base class. Why?
A derived class usually larger than base class, since is normally adds data members
and memory function in addition to what it inherits from the base class.
Part – B
1. What is a friend function? What are the merits and demerties of using friend function?
2. Explain about friend class and friend function with eg.?
3. What is inline function? Explain
4. Compare object oriented methodology with structure programming.
5. Write a program in c++ to input a four digit number and to write the same in words.
6. What is function polymorphism? explain with suitable eg
7. Create a class student and write a c++ program to read and display all the students in
your class.
8. Describe briefly the features of input/output supported by C++
9. explain the nested classes with suitable eg.
10. write a C++ program to add two complex number using the concept of passing and
returning objects in member function
11. what are access specifiers?how are the used to protect data in C++?
12. Explain with an eg, How you would create space for an array of objects using pointer.
13. explain the following with eg
Pointer to object
Array of pointers
Pointer to object members
14. Explain the following with an eg.
a. copy constructor
b. parameterized constructor
c. default argument constructor
d. dynamic constructor
15. what are virtual functions? Give an eg to highlight its need?
16. give the hierarchy of console stream class
17. Explain how exceptions are handled in c++. Give examples to support your answer.
18. Implement a String class. Each object of this class will represent a characters string.
Data members are the Length of the string and the actual characters String In addition to constructors, destructor access function and a print function include a subscript function.
19. Explain Method overriding in Java with an eg.
20. Construct the pictorial representation of Java Virtual Machine.
21. Write a program in java using constructor concept.
22. What are the different statements and its use in java?
23. Illustrate Inheritance in Java with suitable program.
24. Give a explanatory answer to define the difference between Java and C++,
Characteristics of Java and the concepts in java
25. Explain the Life cycle of Thread with an eg
26. Describe package concept to perform arithmetic operations. Explain
how to use it?
27. Explain the different states in Life cycle of applet?
28. Define Interfaces? Explain the extension of interfaces, implementation and accessing it.
29. What are the Different Exceptions caught, Explain the types with eg program.
30. Explain try, catch and finally statements with eg.
No comments:
Post a Comment