2 MARKS Oops
2 MARKS Oops
2 MARKS Oops
com
www.vidyarthiplus.com
Unit I
2 Mark Questions and Answers
1. Give some characteristics of procedure-oriented language.
The characteristics of procedure-oriented language are,
i. Emphasis is on doing things (algorithms).
ii. Larger programs are divided into smaller programs known as functions.
iii. Most of the functions share global data.
iv. Data move openly around the system from function to function.
v. It employs top-down approach in program design.
2. What are the basic concepts of OOPS?
The basic concepts of OOPS are,
i. Objects.
ii. Classes.
iii. Data abstraction and Encapsulation.
iv. Inheritance.
v. Polymorphism.
vi. Dynamic binding.
vii. Message passing.
3. What is an object?
An object is basic run-time entity in an object-oriented system. They may
represent a person, a place, a bank account, a table of data or any item that the program
has to handle. Each object has the data and code to manipulate the data and theses
objects interact with each other.
4. What is a class?
A class is a collection of objects of similar type. Once a class has been defined,
we can create any number of objects belonging to the class. Class is a user-defined data
type and behaves like built-in types of the programming language.
5. What is an encapsulation?
Wrapping up of data and function within the structure is called as encapsulation.
The insulation of data from direct access by the program is called as data hiding or
information binding. The data is not accessible to the outside world and only those
functions, which are wrapped in the class, can access it.
www.vidyarthiplus.com
www.vidyarthiplus.com
6. What is meant by dynamic binding or late binding?
Dynamic binding means that the code associated with a given procedure call is
not known until the time of the call at the run-time.
7. Write the process of programming in an object-oriented language?
The process of programming in an object-oriented language are,
i. Create classes that define objects and their behavior.
ii. Creating objects from class definition.
iii. Establishing communication among objects.
8. List any four advantages of OOPS.
The advantages of OOPS are,
i. The principle of data hiding helps the programmer to build secure
programs that cannot be invaded by code in other parts of the program.
ii. It is possible to have multiple instances of an object to co-exist without
any interference.
iii. Object oriented programming can be easily upgraded from small to large
systems.
iv. Software complexity can be easily managed.
9. What are the features required for object-based programming language?
The features required for object-based programming are,
i. Data encapsulation.
ii. Data hiding and access mechanisms.
iii. Automatic initialization and clear up of objects.
iv. Operator overloading.
10. Give any four applications of the OOPS.
The four applications of OOPS are,
i. Real-time systems.
ii. Simulation and modeling.
iii. Object-oriented databases.
iv. AI and expert systems.
www.vidyarthiplus.com
www.vidyarthiplus.com
11. What are the operators available in C++?
The operators available in C++ are,
i. :: - Scope resolution operator.
ii. :: * - Pointer-to-member declarator .
iii. ->* - Pointer-to-member operator.
iv. .* - Pointer-to-member operator.
v. delete - Memory release operator .
vi. endl - Line feed operator
vii. new - Memory allocation operator
viii. setw - Field width operator
12. What is a default argument?
Default argument assigns a default value to the parameter, which does not have
matching argument in the function call. Default values are specified when the function
is declared.
Example:
float amount (float principle, int period, float rate=0. 15)
{
}
13. What is constant argument?
Keyword is const. The qualifier const tells the compiler that the function
should not modify the argument. The compiler will generate an error when this
condition is violated. This type of declaration is significant only when we pass
arguments by reference or pointers
Example:
int strlen (const char *p);
14. How do you create an object?
Once the class has been declared, we can create object for a class using the
class
name.
Example:
classname x; //memory for x is created
www.vidyarthiplus.com
www.vidyarthiplus.com
15. How the class is specified?
Generally class specification has two parts. They are,
i. Class declaration - It describes the type and scope of its member
ii. Class function definition - It describes how the class functions are
implement
ed The general
form is:
class class_name
{
private:
variable
declarations;
function
declaration;
public:
variable
declaration;
function
declaration;
};
16. How do you access a class member?
We can access the member function by using the following syntax:
Syntax:
Object-name.
Function-name
(actual
arguments); Example:
x.getdata (100, 75.5);
17.How is the member functions defined?
Member functions can be defined in two ways. They are,
i.
Outside the class definition - Member function can be defined by
using scope resolution operator (::).
General format is
return type class_ name:: function-name (argument declaration)
{
..//function body
}
ii.
www.vidyarthiplus.com
18. What are the features of static data member?
The features of static data member are,
i. It is initialized to zero when the first object is created
ii. Only one copy of that member is created for the entire class
iii. It is only visible within the class
iv. It is stored separately rather than objects
19.What are the situations that inline functions may not work?
The situations that inline functions may not work is,
i. For function returning values, if a loop, a switch, or a goto exists.
ii. For function not returning values, if a return statement exists.
iii. If function contains static variables.
iv. If inline functions are recursive.
v.
20.What is a namespace?
The namespaces are used to group the entities like class, variables, objects,
function under a name.
21.What is abstract class?
The class that does not specify the implementation details,but specifies only
what are the operation in the particular data structure.
www.vidyarthiplus.com
www.vidyarthiplus.com
Unit II
1. Define Constructor.
A constructor is defined as a special member of a class, which has no return type.
It can be used to initializes an object immediately upon creation.
2. Write some special characteristics of constructor.
Some special characteristics of constructor are,
i. They should be declared in the public section.
ii. They are invoked automatically when the objects are created.
iii. They do not have return types, not even void and therefore, and they
cannot return values.
iv. They cannot be inherited, though a derived class can call the base class
v. They can have default arguments.
vi. Constructors cannot be virtual function.
3. How the objects are initialized dynamically?
The objects an initialized dynamically to call parameterized constructor or
methods we should the pass values to the object ie, for the constructor integer add(int a,
int b) it is invoked by integer a (10, 18). This value can be get during run time. i.e., f or
above constructor
Example:
int
p,q;
cin>>p>>q;
integer add(p,q);
4. What is meant by operator overloading?
Operator overloading is the mechanism of giving such special meanings to an
operator is known. It provides a flexible option for the creation of new definitions for
C++ operators.
5.
iii.
iv.
Conditional operator (? :)
www.vidyarthiplus.com
www.vidyarthiplus.com
iii.
iv.
www.vidyarthiplus.com
www.vidyarthiplus.com
Function statements;
}
11. What are the conditions to satisfy the type casting function?
The conditions to satisfy the type casting function are,
i. It must be a class member.
ii. It must not specify a return type.
iii. It must not have any arguments.
12. What is Friend function? Write the syntax.
A function that has access to the private member of the class but is not itself a
member of the class is called friend functions. Friend function is preceded by the
keyword friend.
The general form is:
friend datatype function name (object dec);
www.vidyarthiplus.com
classname::virtual-function();
www.vidyarthiplus.com
www.vidyarthiplus.com
20.What is a scope resolution operator?
Scope resolution operator is used to uncover the hidden variables. It also allows
access to global version of variables. Scope resolution operator is used to define the
function outside the class.
Syntax:
return type <class name> : : <function name>
Example:
#include<iostream. h>
int m=10; // global variable m
void main ( )
{
int m=20; // local variable m
cout<<m=<<m<<\n;
cout<<: : m=<<: : m<<\n;
}
Output:
20
10 (: : m access global m)
www.vidyarthiplus.com
www.vidyarthiplus.com
Unit III
1. What are the various traditional error handling methods?
The various traditional error handling methods are,
i. Returning error number.
ii. Global flag manipulation.
iii. Abnormal termination.
2. What is the importance of exceptional handling?
The importance of exceptional handling is,
i. Divide the error handling.
ii. To provide unconditional termination and programmer preferred termination
iii. For separating error reporting and error handling.
iv. To solve the object destroy problem.
3. What are the three keywords used for exception handling mechanism?
The three keywords used for exception handling mechanism are,
i. try
ii. throw
iii. catch
www.vidyarthiplus.com
8. Write the syntax for function Template.
The syntax for function Template is,
Template <class T, ..>
Return Type Fun_Name (arguments)
{
. // body of the template
}
9. What are the error handling function in C++?
The error handling function in C++ is,
i.
eof()
ii. fail()
iii. bad()
iv.
good()
10. What are the rules for virtual function?
The rules for virtual function are,
i.
They cannot be static members.
ii. They are access by using object pointers.
iii. A virtual function can be a friend of another class.
11. What are Streams?
Stream is a mechanism, which supplies the input data to a program and presents
the processed data in the desired form.
12. What are the file stream classes in C++?
The file stream classes in C++ are,
1. filebuf
2. fstreambase
3. ifstream
4. ofstream
5. fstream
13. What is the Stream objects used in C++?
The Stream objects used in C++ is,
i.
cin
ii. cout
iii. cerr
iv.
clog
14. List out the ways of Class Template inheritance.
The ways of Class Template inheritance are,
i. Derive a class template from a base class, which is a template class
ii. Derive a class template from the base class , which is a template class, add
more template members in the derived class
iii. Derive a class template from a base class which is not a template class, and
add template members to that class
iv. Derive a class template from a base class which is a template class and
restrict the template feature.
www.vidyarthiplus.com
www.vidyarthiplus.com
Task Performed
Specifies the required number of fields to be used
while displaying the output value.
Specifies the number of digits to be displayed after
the decimal point
Specifies a character to be used to fill the unused area
of a field.
Sets format flag that control the form of output
display
Clears the specified flag
www.vidyarthiplus.com
Unit IV
1. What is Java?
Java is a high-level, third generation programming language, like C,
FORTRAN, Smalltalk, Perl, and many others. You can use Java to write computer
applications that crunch numbers, process words, play games, store data or do any of
the thousands of other things computer software can do.
2. What are the features of Java?
The features of Java are,
i. Simple.
ii. Object Oriented.
iii. Platform Independent.
iv. Robust.
v. Multithreaded.
vi. Secure.
3. What are the various applications of Java?
The various applications of Java are,
i.
Applets
ii.
Networking
iii. Internationalization
iv.
Security
v.
Object serialization
vi.
Java Database Connectivity (JDBC)
4. What is meant by virtual machine?
A Java virtual machine (JVM), an implementation of the Java Virtual Machine
Specification, interprets compiled Java binary code (called bytecode) for a
computer's processor (or "hardware platform") so that it can perform a Java program's
instructions
5. What are the two components of Java platform?
The two components of Java platform are,
i.
The Java Virtual Machine
ii.
The Java Application Programming Interface (API)
6. What is bytecode in Java?
Java bytecode is the form of instructions that the Java virtual machine executes.
Each bytecode opcode is one byte in length, although some require parameters,
resulting in some multi-byte instructions. Not all of the possible 256 opcodes are used.
7. What is an Object?
An object consists of data and functions known as methods which use or change
the data. (Methods are similar to procedures or functions in other languages.) Objects of
the same kind are said to have the same type or be in the same class. A class defines
what data can be in an object, and what operations are performed by the methods. One or
more objects can be created or instantiated from a class.
www.vidyarthiplus.com
www.vidyarthiplus.com
Definition
one-byte signed two's complement integer
two-byte signed two's complement integer
4-byte signed two's complement integer
8-byte signed two's complement integer
4-byte IEEE 754 single-precision float
8-byte IEEE 754 double-precision float
2-byte unsigned Unicode character
www.vidyarthiplus.com
www.vidyarthiplus.com
13. What is an array?
An array is a special object containing a group of contiguous memory locations
that have the same name and the same type and a separate variable containing an integer
constant equal to the number of array elements. The elements of Java arrays are
numbered starting from 0.
Example:
www.vidyarthiplus.com
www.vidyarthiplus.com
20. What are the advantages of inheritance?
The advantages of inheritance are,
i. It permits code reusability.
ii. Reusability saves time in program development.
iii. It encourages the reuse of proven and debugged high-quality software,
thus reducing problem after a system becomes functional.
www.vidyarthiplus.com
www.vidyarthiplus.com
Unit V
1.What are packages?
A Java package is a mechanism for organizing Java classes into namespaces
similar to the modules of Modula. Java packages can be stored in compressed files called
JAR files, allowing classes to download faster as a group rather than one at a time.
2. List out the Java packages.
The Java packages are,
i.
java.lang
ii. java.io
iii. java.awt
iv.
java.net
v.
java.applet
vi.
java.rmi
3.What are Encapsulation, Inheritance and Polymorphism?
i. Encapsulation is the mechanism that binds together code and data it
manipulates and keeps both safe from outside interference and
misuse.
ii. Inheritance is the process by which one object acquires the
properties of another object.
iii. Polymorphism is the feature that allows one interface to be used for
general class actions.
4.What is the use of super keyword?
A Java(TM) programming language keyword used to access members
of a class inherited by the class in which it appears.
5.What do mean by overriding methods?
The ability of a subclass to override a method in its superclass allows a
class to inherit from a superclass whose behavior is "close enough" and then
supplement or modify the behavior of that superclass.
6.List out the various types of inheritance.
The various types of inheritance are,
i. Simple inheritance - One base class and one derived class
ii. Multilevel inheritance - a sub class derived from another sub class
iii. Hierarchical inheritance - two or more sub class have the same base class
7.Define Interface.
An Interface is defined as a named collection of method definitions
(without implementations). An interface can also declare constants. All the
methods declared in the interface are abstract methods by default. And all the
data members are static final members.
www.vidyarthiplus.com
www.vidyarthiplus.com
8. How multiple inheritance is implemented in java?
A class can implement more than one interface (the Java platform supports
multiple inheritance for interfaces), so the implements keyword is followed by
a comma-separated list of the interfaces implemented by the class.
9. What is an Exception?
An Exception is an event that occurs during the execution of a program that
disrupts the normal flow of instructions during the execution of a program.
10. How an Exception is handled in java?
A program can catch exceptions by using a combination of the try, catch, and
finally statements. The try statement identifies a block of code in which an exception can
occur. The catch statement identifies a block of code, known as an exception handler that
can handle a particular type of exception.
11. What is the use of finally block?
The finally statement identifies a block of code that cleans up regardless of
whether an exception occurred within the try block. A try statement must be accompanied
by at least one catch statement or a finally statement and may have multiple catch
statements.
12. How Threads are created in Java?
Theads are created in two ways,
i. extending the Thread class
ii. implementing Runnable interface.
13.What is Thread pool?
A Thread pool is a managed collection of threads that are available to perform
tasks. Thread pools usually provide,
i. Improved performance when executing large numbers of tasks due to
reduced per-task invocation overhead.
ii. A means of bounding the resources, including threads, consumed
when executing a collection of tasks.
14. Define Dead Lock.
A Dead Lock is defined as a special type of error that relates specifically to
multitasking is dead lock, which occurs when two threads have a circular dependency on
a pair of synchronized objects.
15. What do you mean by Thread Scheduling?
Execution of multiple threads on a single CPU in some order is called Thread
scheduling. The Java runtime environment supports a very simple, deterministic
scheduling algorithm called fixed-priority scheduling. This algorithm schedules threads
on the basis of their priority relative to other Runnable threads.
www.vidyarthiplus.com
www.vidyarthiplus.com
16.What are the various states of a thread?
The various states of threads are shown below:
www.vidyarthiplus.com
www.vidyarthiplus.com
CS6456 Object Oriented Programming Question Bank - 16 Marks Questions
Unit I
1.Illustrate the function overloading concept with a C++ program to find the volume of cube
and cylinder
2.Explain the basic concepts of oops with suitable Examples
3.Write a C++ program to construct student mark list for three subjects. Write the program to
display name,rollno,marks,avg and total.Use clss and objects.
4.Explain the control structures in C++
5.Define Call by reference and Return by reference.
Unit II
1.Explain the Friend function concept with an example program.
2.What is Dynamic Initialisation of objects?Give a program to illustrate your answer.
3.Explain the constructor concept with its types with example programs.
4.Explain the concept of objects as functional arguments.
5.Write a C++ program to manage a bank account using classes and objects.
Unit III
1.Explain virtual function concept with a program to find the distance between two objects.
2.Explain the Inheritance types with example programs for last three types.
3.What do u meant by operator overloading?what are its types?Explain the types with eg
programs.
4.Expalin single and multiple Inheritance with an example of your own.
5.Describe manipulation of strings with overloading the following operators:<<,>>,+,Unit IV
1.Explain Method overriding in Java with an eg.
2.Construct the pictorial representation of Java Virtual Machine.
3.Write a program in java using constructor concept.
4.What are the different statements and its use in java?
5.Illustrate Inheritance in Java with suitable program.
6.Give a explanatory answer to define the difference between Java and C++,Characteristics of
Java and the concepts in java.
Unit V
1.Explain the Life cycle of Thread with an eg
2.Describe package concept to perform arithmetic operations.Explain how to use it?
3.Explain the different states in Life cycle of applet?
4.Define Interfaces?Explain the extension of interfaces,implementation and accessing it.
5.What are the Different Exceptions caught,Explain the types with eg program.
6.Explain try, catch and finally statements with eg.
www.vidyarthiplus.com