Code: DC-12                                                                                    Subject: OOPS THRU JAVA

Time: 3 Hours                                                                   Flowchart: Alternate Process: December 2005                                  Max. Marks: 100

NOTE: There are 9 Questions in all.

·      Question 1 is compulsory and carries 20 marks.

·      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            State which of the statement is true and which are false.                                  (2x10)

a.       Constructors cannot be overloaded.     

 

b.      In evaluating a logical expression of the type

                                                                                 boolean_expression1 || boolean_expression2  

                                                                       both the expressions are not necessarily always evaluated.

                                                                

c.       It is legal to assign a subclass object to a super class reference. 

                                                                                    

d.      A protected member of a class is available to the subclasses of the same package only.

        

e.       All the command-line arguments are passed as strings.

                            

f.        Every method of a final class is also final.

       

g.       When we implement an interface method, it should be declared as public.

 

             h.  An interface cannot extend another interface.

 

             i.   Internally, Java uses pointers (addresses) to store references to objects.                  

 

j.        Every class of a Java program can be stored in a different file with the name of the file same as that of the class in it followed by the extension .java.

 

 

Answer any FIVE Questions out of EIGHT Questions.

Each question carries 16 marks.

  Q.2     a.   What is the output of the following code segments? Justify your answers.

                (i) class A{

                     void method(int x){ System.out.println(“x = “ + x); }

                     }

                     class B extends A {

                           void method(int y) { System.out.println(“y = “ + y); }

                           void method(String s) { System.out.println(“s = “ + s); }

                           public static void main(String args[ ]) {

                                 A a1 = new A();

                                 A a2 = new B();

                                 a1.method(1000);

                                 a2.method(2000);

                     }

                   }

               (ii)  class A{

                     static int m = 10, n = 20;

                     public static void main(String args[ ]) {

                           int m = 30;

                           System.out.println(“m + n = “ + (m + n));

                     }

                   }                                                                                                                           

 

               (iii) try {

                     int x = 0;

                     int y = 10 / x;

                     System.out.println(“Division by zero error”);

               }

               catch (ArithmeticException e) {

                     System.out.println(“Catch block”);

                   }                                                                                                                       (6)

 

             b.   When the order of execution of the constructors in a class hierarchy is same whether or not super() is used, then why is it provided by Java?           (3)

 

             c.   What is polymorphism? How does Java implement polymorphism?                     (7)

 

  Q.3     a.   Identify and correct the errors in the following code segments.

                (i)  switch(c) {

                     case ‘a’: aNo++;

                     case ‘e’: eNo++;

                     default: iouNo++;

                   }

                   (ii) class test {                                                                                                       

                     public static void main(String args[ ]) {

                           int   x =10, y = 20;

                           System.out.println(“Product of x and y = “ + mul(x, y));

                     }

                        int mul(int a, int b) {return (a * b); }

                   }                                                        

 

                  (iii)  byte b = 10;

                           b = b * 10;

 

               (iv)  class Square {

                     private Square( ) { }

                     int area(int side) { return (side * side); }

               }

               class Area {

                     public static void main(String args[ ]) {

                           Square s = new Square();

                           int area = s.area(10);

                           System.out.println(area);

                     }

                   }

               (v)  int m = 100;

                     while (true) {

                                 if (m < 0) continue;

                           m = m -10;

                     }

                        System.out.println(“m = “ + m);                                                                   (10)

 

             b.   What are narrowing conversions? Explain with the help of examples.                   (3)

 

             c.   Briefly explain the significance of this keyword.                                                  (3)          

 

   Q.4    a.   What are command line arguments? Write a Java program to read in the command line arguments and display them along with the number of characters in each argument.                                    (8)

 

             b.   Assume that a bank maintains two kinds of account for its customers, one called savings account and the other current account. The savings account provides simple interest. Current account holders should also maintain a minimum balance of Rs. 1000/- and if the balance falls below this level, Rs. 20/- is deducted from the account.

                   Create a class Account that stores customer name, account number and balance. From this derive the classes Curracct and Savacct  to make them more specific to their requirements. Include the necessary methods in order to achieve the following tasks:

(i)                  Compute and deposit interest in Savacct.

(ii)                Check for the minimum balance, impose penalty, if necessary, and update the balance in Curracct.                          (8)

 

  Q.5     a.   Write a Java program to display the contents of a file “test.txt” along with the line numbers.             (8)

 

             b.  What are static methods? Why cannot a static method refer to this?                    (5)

 

             c.   Briefly explain the meaning of the following statement:

                   Stack my_stack = new Stack(); where Stack is a class.                                  (3)

       

  Q.6     a.    Write a Java program to return the number after reversing its digits.                     (7)

 

             b.   Briefly explain the three uses of break statement.                                                (6)

 

             c.   Why is main() defined as public static?                                                             (3)                      

 

  Q.7     a.   Write a Java program to produce the following output:

                   A

                   A  B

                   A  B  C

                   A  B  C  D

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

 

             b.   Briefly explain the <<, >> and >>> operators, and which arithmetic operations do they correspond to?                                                                  (5)

 

             c.   What is Unicode? Why Java uses Unicode and not ASCII code?                       (3)

 

  Q.8     a.   Differentiate between the following:

(i)        abstract and non abstract classes.

(ii)       error and exception.

(iii)               Java applets and Java program.

(iv)              Encapsulation and data hiding.                                                        (12)

 

             b.   What do understand by bytecode? What are the advantages of the bytecode over an executable code?                                                                 (4)

 

  Q.9           Write short notes on the following:

(i)                  The finalize() method

(ii)                Access specifiers

(iii)               Packages

(iv)              Exception handling                                                                               (16)