OOPS DECEMBER 2009
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: (2 10)
a. Which of the following is a valid octal number?
(A) 080 (B) 0A6
(C) 091 (D) 072
b. Consider the following class definition:
class A {
A(int x) { … }
A(int x, int y) { … }
Which of the following statements cannot be used to construct objects of type A?
(A) A a = new A(10); (B) A a = new A();
(C) A a = new A(20, 30); (D) None of the above
c. All the objects of a class use the same copy of a(n) ___________ variable.
(A) final (B) protected
(C) static (D) public
d. A package in Java is a collection of __________ .
(A) Output files (B) Class files
(C) Text files (D) Source files
e. Which of the following is true?
(A) Error and Exception are subclasses of Throwable class.
(B) Error and Throwable are subclasses of Exception class.
(C) Throwable and Exception are subclasses of Error class.
(D) None of the above.
f. What will be the output of the following program?
class demo{
public static void main(String args[]) {
boolean a = true, b = false;
System.out.println("a = " + a);
return;
System.out.println("b = " + b);
}
}
(A) a = trueb= false
(B) a = true
(C) a = true b= false
(D) Program won’t compile giving message "unreachable statement".
g. Which of the following is an illegal flow control statement?
(A) break; (B) break label;
(C) continue; (D) continue (label);
h. To achieve multiple inheritance in Java, __________ are used.
(A) interfaces (B) Constructors
(C) Arrays (D) Operators
i. Which of the following are passed by reference in Java?
(A) Integers (B) Arrays
(C) Booleans (D) Characters
j. Identify the incorrect statement among the following statements.
(A) Java classes need not have a main() method.
(B) Variables cannot be defined within the for loop.
(C) Abstract classes cannot be instantiated.
(D) There can be any number of catch clauses after a try block.
Answer any FIVE Questions out of EIGHT Questions.
Each question carries 16 marks.
Q.2 a. Briefly explain the three uses of break keyword. (6)
b. Identify the error(s), if any, in the following code segments. (4)
(i) int x = 10, y = 20;
System.out.println("Output: " + (x + y)++);
(ii) class box {
int length, height, depth;
private box() { length = height = depth = 0; }
int area() { return length * height * depth;}
}
class demo{
public static void main(String args[]) {
box b = new box();
System.out.println("Area = " + b.area());
}
c. What are the various uses of super keyword? Explain with the help of examples. (6)
Q.3 a. Briefly explain the two main features of Java that make it a useful programming language for the Internet. (4)
b. What is a static block? What is it used for? (3)
c. Differentiate between the following:
(i) call by value and call by reference
(ii) throw and throws
(iii) do...while and while loops (3 3)
Q.4 a. Distinguish between single inheritance and multiple inheritance. Which feature(s) of Java helps to realize the benefits of multiple inheritance? Explain with an example. (8)
b. When an overloaded method is invoked, how does Java decide? Which version of overloaded methods is to be called? What are the advantages of having different methods with the same name? (4)
c. What is the purpose of garbage collection in Java? (4)
Q.5 a. How does a package help in organising classes? Explain with the help of a suitable example. (4)
b. What is an applet? How is it different from Java application program? (4)
c. Find out the value of a after each operation (assume for each operation initial value of a is 22 and b is 5).
(i) a << 3
(ii) a ^ b (4)
d. What are the four categories of visibility Java addresses for class members? (4)
Q.6 a. What do you understand by recursion? What is the output of the following code segment? Show the steps also. (8)
class recur{
public static void main(String args[]){
int sum = meth(3, 5);
System.out.println("sum= " + sum);
}
static int meth(int a, int b){
int result;
if (a == -b)
result 0;
else
result = a + meth(a, (b - 1));
return result;
}
}
b. Design a class Complex having a real part (x) and an imaginary part (y). Provide methods to perform the following on complex numbers:
(i) Add two complex numbers.
(ii) Multiply two complex numbers.
(iii) Display a complex number in the form: x + i y. (8)
Q.7 a. Explain the term polymorphism and different ways Java implements polymorphism. (8)
b. How is exception handling done in Java using the keywords try, throw and catch? (8)
Q.8 a. Define a class Person having name as a data member. Inherit two more classes Student and Employee from Person. To the class Student, add data members course, marks and year; and to the class Employee, add data members department and salary. Write display() method in all the three classes to display the relevant details of the corresponding class. Provide the necessary methods to show dynamic method dispatch concept. (10)
b. What is the significance of this keyword? Where is it used? Explain with the help of an example. (6)
Q.9 Write short notes on the following:
(i) Byte streams and character streams
(ii) Lifetime of variables
(iii) PrintWriter class
(iv) Extending an interface (4
Comments
Post a Comment