You are on page 1of 4

R.M.D.

ENGINEERING COLLEGE
RSM NAGAR, KAVARAIPETTAI 601 206

5th Semester B.E Model Examination- October 2012

KEY
Sub. Title Sub. Code Time : Object Oriented Programming : CS2311 : 180 mins Date : Branch : EEE Max.Marks : 100

Answer all questions


Part A (10 x 2 = 20 Marks) 1. When will the destructor be called? Is it implicit or explicit?
Destructor will be called when the object goes out of scope or when the object is destroyed. It will be called implicitly. 2. With respect to C++ distinguish objects from classes Classes are template or blueprint. Memory will not be allocated. Object are created from class and memory is allocated. Example: Class student{ }; Student ganesh; 3. What is virtual base class?
Virtual base classes, used in virtual inheritance, is a way of preventing multiple "instances" of a given class appearing in an inheritance hierarchy when using multiple inheritance.

4. What is pure virtual function?


Function without definition is called pure virtual function. It should be declared as Virtual returntype fun_name()=0; State the purpose of namespaces with an example. They are used to avoid name conflict. Example: std is a namespace that has cout object What is purpose of STL? STL stands for Standard Template Library. STL contains collection Generic classes. Example: List and Queue What is byte code? Mention its advantage. The output of java compiler is .class file which is called as byte code. Once generated, byte code can run on any system( platform independent) State the properties of static method? Static method can call only other static method and static data member. It cant use this and super keyword How is the keyword super used in java? Super keyword is used to access the base class member from the derived or sub class. Example. Super.baseclassmember

5.

6.

7.

8.

9.

10. What are wrapper classes in Java?


A wrapper class treats the data type as object. Every data type has its associated Wrapper class. Example: Integer is wrapper class for integer data type. Integer.parseInt(string) _ to convert string to int Part B (5*16= 80 Marks) 11. (a) Explain the features of object oriented programming. Describe how each of these is implemented in C++ and Java. (16) Class Object Data encapsulation Data abstraction Inheritance Polymorphism Message passing Or (b) Write a C++ program to define overloaded constructor to perform string initialization, string copy and string destruction. (16) Class string { Char *name; Public: String() {} String( char *p) { //allocate memory and initialize } String( string& s) { //code for copy one obj to ther } String() { // code to destroy object } 12. (a) Explain runtime polymorphism with example program in C++ (16) Definition (2) Types of polymorphism (2) Concept (2) Program (10) Or (b) Write a C++ program as follows to perform arithmetic operations on Rational numbers of type a/b, where a and b are integers. (i) Define a class by Rational Number. (4) (ii) Use operator overloaded methods for addition and subtraction. (6) (iii) Write a main program to demonstrate the use of this class and it methods. (4)

(iv) Give a sample output. Class Rational { Int num,deno; // a/b Rational (int n, int d) { Num=n;deno=d; } Rational operator+(Rational r) { //add rational numbers and return object } Rational operator-(Rational r) { //add rational numbers and return object } } Main() { Rational r1 (1/2) ------R3=r1+r2 }

(8)

13. (a) Write a C++ program to demonstrate file handling as follows: get strings as input from the user, store them in a file, retrieve them and display them. (16) Steps: <create a text file> Get the string from user using getline() Open file in read mode Write string to file Close the file Open the file again in write mode Read the data and display it. Close the file Or (b) Explain the exception handling mechanism available in C++ with suitable examples (16) Define Exception (2) Syntax (4) Try{ } Catch() { } (10)

Program

14. (a) Write a java program to create two single dimensional arrays, initialize them and add them; store the result in another array (16) Int a[]=new int a[5] { 1,2,3,4,5} Int b[]=new int b[5]{1,2,4,5,6} For(; ; ;) { C[i]=a[i]+b[i]; } Or (b) (i) Describe the structure of a typical Java program and give the steps to execute it. (8) Structure of java program (4) Different sections in java program Steps to execute program (4) (ii) Explain with example how packages are created. Definition (2) Steps (2) Example (4) 15.(i) Describe the single inheritance with an example Java program (8) Definition (2) Syntax (1) Class subclass extends superclass { } Program (5) (ii) Describe the concept of interface with the syntax. Definition (2) Concept/properties (2) Example (4) Or (b) Explain the following with example (i) Streams and IO (6) Definition of streams (2) Types of streams (2) byte and char streams Explanation about stream classes(2) (ii) Threads concept (10) Definition and example (2) States (2) New, runnable, blocked, wating, timed waiting,terminated Program (6)

(8)

You might also like