Flowchart: Alternate Process: DECEMBER 2007
Code: 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.          Java uses _____________ character set.

 

        (A)  Unicode                                    (B)  ASCII

        (C)  EBCDIC                                   (D)  ISCII

 

b.         The class which is at the top of the exception class hierarchy is

 

        (A)  Error                                         (B)  Exception

        (C)  Throwable                                 (D)  None of the above

 

c.          The data type of the result obtained on applying relational operator on two integers is

 

        (A)  int                                             (B)  float

        (C)  boolean                                     (D)  char

 

d.         Which of the following is the correct way of initializing a two dimensional array of integers with 3 rows and 5 columns?

 

        (A)  int a[3][5];                                 (B)  int a[][] = new int [3] new int [5];

        (C)  int a[][] = new [3][5];                (D)  int a[][] = new int [3][5];

 

e.          What does the statement Box myBox do?

 

        (A)  Creates reference of type Box

        (B)  Creates reference of type myBox

        (C)  Creates an object of type Box

        (D)  Creates an object of type myBox                                                                  

 

f.           Which of the following is not true for static members of a class?

 

     (A)  Static data members can be used independently of any object of the class.

     (B)  All instances of a class share the same copy of the static data member.

     (C)  Static methods can access static data members only, but can call non static methods.

     (D)  Static methods cannot refer to this or super in any way.

 

g.          The class at the top of the byte stream hierarchy for reading data is

 

        (A)  Reader                                      (B)  BufferedReader

        (C)  BufferedInputStream                 (D)  InputStream

h.          All the standard Java classes included with Java are stored in a package called

 

        (A)  java                                           (B)  java.lang

        (C)  java.util                                     (D)  None of the above

 

i.            By using which of the keyword it is possible to prevent inheritance of a class?

 

        (A)  final                                           (B)  private

        (C)  static                                         (D)  abstract

 

j.           Which of the following is a valid declaration of the main method?

 

        (A)  public static void main(char args[ ])

        (B)  public static void main(String args[ ])

        (C)  public static void Main(String args[ ])

        (D)  public static void main(String args)

 

 

 

Answer any FIVE Questions out of EIGHT Questions.

Each question carries 16 marks.

 

 

  Q.2     a.   What do you understand by object oriented programming? What are the three main principles of OOPS?                                                              (8)

 

             b.   Explain how exception handling is carried out using the keywords try, catch and throw.                   (8)

                                                                                                                                                

  Q.3           Differentiate between the following:

                    (i)    constructors and methods

                    (ii)    multiple and multi-level inheritance

                    (iii) interfaces and classes

                 (iv) scope and lifetime of variables                                                                    (16)

                  

  Q.4     a.   Design a class Person having name and DOB as members.  Derive two more classes: student and Employee from Person.  student has members course and grade; and Employee has members department and salary.  Write appropriate methods in classes to initialise and retrieve data members.                      (5)

                  

             b.   What is the use of “this” keyword? Explain its use with the help of an example. What are the restrictions on the usage of “this”?                              (6)                                                             

 

             c.   How is the following expression computed in Java using type promotion rules?

                   double result = (f*b) + (i/c) – (d*s);

                   where f is a float, b is a byte, i is an int, c is a char, d is a double and s is a short variable.                (5)

 

  Q.5     a.   Write a program in Java to read in numbers from the user and store them in a file named “test.txt”. Store the sum of the numbers at the end of the file.                                                           (10)

 

b.      What will be the output of the following code segments?                                     (6)

                   (i)  public static void main(String args[ ]) {

                                 int   n = 5;

                                 System.out.println("New n = " + (n << 4 >> 3 << 2));

                         }

              (ii)  public static void main(String args[ ]) {

                           int   a, b, c;

                          a = b = c = 1;

                          if (c = = 1 & b++ < 6)

                                a = 5;

                          System.out.println(a + " " + b + " " + c);

                    }

 

              (iii)    class A{

                       static int   x = 100, y = 200;

                       public static void main(String args[ ]) {

                          int   y = 300;

                           System.out.println("x + y = " + x + y);

                       }

               }                                                                                                                        

 

  Q.6     a.   When do we declare a member of a class static? Give an example. What are the restrictions normally imposed on static member functions of a class?                                                                  (6)

            

             b.   What are abstract classes? What is their need?                                                   (6)

 

             c.   How can multiple inheritance be implemented in Java?                                        (4)

                                                          

  Q.7     a.   What is dynamic method dispatch? Explain with the help of an example.              (6)

 

             b.   How does the modifier ‘final’ effect the behaviour of

               (i)    data member of a class

               (ii)    method of a class

                   (iii)   class itself.                                                                                                 (6)

 

             c.   What is the difference between call by value and call by reference? When does Java use each?                                                                  (4)

 

  Q.8     a.   Write a program in Java to print the following:

                   1

1            2

1      2       3

The number of rows to be printed is passed as an argument to the program.        (8)

       


 

               b. Consider the following code segment:

package  p1;

public class X{

        int                     i;

        public char        c;

        private float      f;

        protected byte  b;

}

package p2;

class Y extends X{ … }

 

Which variables of class X are inherited in class Y and what is their accessibility?                            (4)

 

             c.   What are constructors? The constructors are almost always public members of the classes. What goes wrong if they are defined as private?     (4)

 

  Q.9           Write short notes on the following:

(i)                  Switch statement

(ii)                Streams

(iii)               Recursion

(iv)              Type Casting                                                                                   (4  4)