Code: DC-12                                                                                     Subject: OOPS THRU JAVA Flowchart: Alternate Process: JUNE 2007

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 Virtual Machine (JVM) executes

 

                   (A)  Machine code                              (B)  Java program

(C)    Bytecode                                     (D)  None of the above

       

b.      It is not possible to create objects of

 

(A)    Final class                                    (B)  Abstract class

(C)  Public class                                  (D)  Adapter class

            

             c.   Which of the following represent the correct sequence of statements to compile “a.java” and then execute it?

                         

(A)    C:\>javac a                                  (B) C:\>javac a.java

C:\>java a.java                                    C:\>java a

(C) C:\>java a                                     (D) C:\>java a.java

        C:\>javac a.java                                  C:\>javac a

            

             d.   Which of the following is same as the statement :

                         for(j = 0; j <= N; j++) { System.out.println(“Test” + j); }

                                                                                                                 

(A)  j = 0;

       while (j <=N) j++; System.out.println(“Test” + j);

(B)  j = 0;

       while (j <=N) System.out.println(“Test” + j); j++;

(C)  j = 0;

       while (j<=N) {j++; System.out.println(“Test” + j);}

(D)  j = 0;

       while (j<=N) { System.out.println(“Test” + j); j++; }

 

             e.   In a class hierarchy, when a method in a subclass has same name and type signature as a method in its superclass then

                  

(A)     Superclass method is said to override the subclass method.

(B)     Superclass method is said to overload the subclass method.

(C)     Subclass method is said to override the superclass method.

(D)    Subclass method is said to overload the superclass method.

 


             f.    Variables defined inside an interface declaration are implicitly __________ in the implementing class.

 

(A)     Both final and static                      (B) Only final

(C)  Only static                                    (D) Abstract

 

             g.   The clause used to list type of exceptions that a method might through is

 

(A) try                                                 (B) catch

(C) throw                                            (D) throws

 

             h.   The escape sequence starting with \u represents a

 

(A)    Hexadecimal number                    (B) Unicode

(C)  Octal number                               (D) Carriage return

 

             i.    To be able to use classes in a package, the package has to be

 

(A)   imported                                       (B)   inherited

(C) implemented                                 (D)   extended

 

             j.    Suppose class sub extends class base. Now if s is a reference of sub and b is a reference of base, then which of the following assignments is illegal?

 

(A)    s = b;                                           (B)  b = new base( );

(C)  b = s;                                           (D)  s = new sub( )

 

 

 

 

 

Answer any FIVE Questions out of EIGHT Questions.

Each question carries 16 marks.

 

 

  Q.2     a.   How does final modifier effect the behaviour of a

(i)                  Method of a class

(ii)                Data member of a class

(iii)               Class itself                                                                          (3  2)

 

             b.   What is the difference between call by value and call by reference? How are simple data type variables and objects of classes passed to methods?  (6)

 

             c.   Find out the errors, if any, in the following code segments and correct them.

                   (i)    class test{

                               private int i, j;

                               int test( ) { System.out.println("Test Program"); }

                           }

                   (ii)   interface A{ void m1(); void m2( ); }

                           interface B extends A { void m3( );}

                           class C implements B {

                                void m2( ) { …}

                                void m3( ) { …}

                           }                                                                                                        (2  2)          

                                                                                                                                                

  Q.3     a.   What do you understand by Dynamic Method Dispatch? Explain with the help of an example.                                                                    (8)

 

             b.   Write a program that creates a new exception NegativeNumberException. This exception is thrown if the number passed to the method “meth” defined in the program is a negative number. (8)

                  

  Q.4     a.   Write a program in Java to count and display the number of uppercase, lowercase, digits and other characters in the file whose name is passed to it through the command line arguments.         (12)

                  

             b.   Explain the significance of defining main method as public static void.                  (4)          

 

  Q.5     a.   Write a method in Java that reads and validates a matrix of size m x m, where m is passes as an argument to the method. A matrix is valid if and only if

(i)                  All diagonal entries are positive.

(ii)                All non diagonal entries are negative or zero.

                   The program should print “The matrix is valid” if it is valid and “The matrix is invalid”, if it is not.                                                                 (10)

 

             b.   Differentiate between the following:

(i)                  error and exception

(ii)                finalize and finally                                                                       (6)

 

  Q.6     a.   What do you understand encapsulation? How does Java ensure restricted access to the data members of a class? Explain briefly.                           (8)

            

             b.   Write a Java program to produce the following output:

                   A

                   B   B

                   C   C   C

                   D   D   D   D

                   The number of rows to be printed is read from the user.                                      (8)

                                                          

  Q.7     a.   Design a class employee. An employee has a name and salary. Write the default constructor, a constructor with two parameters (name and salary) and methods to return name and salary. Also write a method raiseSalary that raises the employee’s salary by a certain percentage. Derive a subclass Manager from employee. Add an instance variable named department to the manager class. Supply a test program that uses theses classes and methods.                                                                             (12)          

 

             b.   What is the difference between keywords this and super?                                 (4)

 

  Q.8     a.   What are recursive functions? Write a recursive function to computer factorial of a number. Trace your function for computing the factorial of 4.                                                             (8)

            


             b.   What is the implication of importing a package using “*”? Will an error occur if a class with same name exists in two different packages that are imported using “*”? Will the error occur at the runtime or the compile time? How can the error be avoided?                                                                          (8)

       

  Q.9           Write short notes on the following:

(i)                  Abstract classes

(ii)                Type Conversions and Casting

(iii)               Static members of a class

(iv)              Relational operators                                                                        (4  4)