Flowchart: Alternate Process: DECEMBER 2008Code: DC12                                                                                      Subject: OOPS THRU JAVA

Time: 3 Hours                                                                                                     Max. Marks: 100

 

NOTE: There are 9 Questions in all.

·      Question 1 is compulsory and carries 20 marks. Answer to Q. 1. must be written in the space provided for it in the answer book supplied and nowhere else.

·      Out of the remaining EIGHT Questions answer any FIVE Questions. Each question carries 16 marks.

·      Any required data not explicitly given, may be suitably assumed and stated.

 

 

 

 

Q.1       Choose the correct or best alternative in the following:                                         (2x10)

              

a.          The range of values for the long type data is

 

        (A)  –231 to 231–1                             (B)  –264 to 264

        (C)  –263 to 263–1                             (D)  –232 to 232–1

 

b.         If m and n are int type variables, what will be the result of the expression m%n, when m=5 and n=2?

 

        (A)  0                                               (B)  1

        (C)  2                                               (D)  None of the above

 

c.          Which of the following operator is overloaded for String objects?

 

        (A)  –                                               (B)  +

        (C)  &                                              (D)  /

 

d.         A control expression is valid for an ‘if’ statement, if it results in a(n):

 

        (A)  integer                                      

        (B)  boolean

        (C)  floating point number                

        (D)  character

 

e.          What is the error in the following class definition?

           abstract class XY

           {

               abstract sum(int x, int y) { }

           }

 

        (A)  Class header is not defined properly

        (B)  Constructor is not defined

        (C)  Method is not defined properly

        (D)  No error                                                                                                      

 

f.           2.0 is a(n) ________ literal

 

     (A)  int                                             (B)  float

     (C)  double                                      (D)  char

 

 

 

g.          Which of the following can be used to rethrow an exception?

 

        (A)  throws                                       (B)  throw

(C)    rethrow                                     (D) finally

 

h.          Which of the following is the superclass for all the classes defined in JAVA?

 

        (A)  object                                       (B)  OBJECT

        (C)  Object                                      (D)  Base

 

i.            Consider the following code:

           interface Area  

           {

                       float compute(float x, float y);

           }

           class Room implements Area

           {

                       float compute(float x, float y)

                       {

                                   return(x * y);

                       }

           }

        What is wrong with the code?

 

(A)     Interface definition is incomplete         

(B)  Method compute() in interface Area should be declared public

        (C)  Method compute() in class Room should be declared public                          

        (D)  All the above

 

j.           Which of the following does not contain error?

 

        (A)  int x[ ] = int[10];                         (B)  int[ ]y = new int[5];

        (C)  x = y = new int[10];                    (D)  int i = new int(10);

 

 

 

 

 

Answer any FIVE Questions out of EIGHT Questions.

Each question carries 16 marks.

 

 

  Q.2     a.   How polymorphism, encapsulation and inheritance work together? Explain with examples.              (8)

 

             b.   What are type promotion rules in Java? Show by example of an expression.        (8)

                                                                                                                                                

  Q.3     a.   Describe any four bitwise operator. What is use of bitwise operator? Explain how Java uses 2’s complement to overcome the problem of zero crossing.                                                                         (8)

 

             b.   Explain the difference between                                                                       (4x2)

                   (i)  The Nested ifs and switch statement

                   (ii) while and do...while

                  

  Q.4     a.   Explain the use of keyword “this”. Use “this” in a program to resolve name space collisions.                                                                       (8)

                  

             b.   What is recursion? Write a recursive program to compute the factorial of a given number.               (8)       

 

  Q.5     a.   What is java Applet? How we can execute Applet?                                            (6)

 

b.      Explain the Java access control mechanism. Write a program to apply the access control on Stack item (Push and Pop).                                   (10)

 

  Q.6     a.   Design a class to represent a person having following attributes:

                   (i) Name  (ii) Address (iii) Date of Birth where Name and Date of Birth are string variables; and Address is an object of ADDRESS class having following fields:

                   (I) House No    (II) Street   (III) Locality  (IV) City    (V) State

                   Assume appropriate data types for them. Write methods in person to initialize the data into various members and to display their content.                  (8)

            

             b.   What is overriding method? Explain the two uses of “final” to

                   (i)  Prevent Overriding

                   (ii) Prevent inheritance

                   (iii) Prevent change in value of data member                                                        (8)

 

  Q.7     a.   Describe multi-level and multiple inheritances with examples.                               (8)

 

             b.   Write a program with two dimensional array to produce the following output                       (8)

                   0

                   1    2

                   3    4    5

                   6    7    8    9

            

  Q.8     a.   Define an interface. What is the major difference between an interface and a class? How java implements an interface?                                             (8)

       

             b.   What is an exception? What is finally used for? What happens if a program throws an exception and there is no exception handler to handle it?         (8)

 

  Q.9           Write short notes on the following:

(i)                  Reading and Writing files

(ii)                Static Block

(iii)               Abstract classes

(iv)              The finalize( ) Method                                                                      (4  4)