How To Exam?

a knowledge trading engine...


Birla Institute of Technology (BIT Mesra) 2007 B.E OBJECT ORIENTED PROGRAMMING - Question Paper

Saturday, 19 January 2013 02:00Web

BIRLA INSTITUTE OF TECHNOLOGY AND SCIENCE, PILANI
FIRST SEMESTER, 2007-2008
COMPREHENSIVE exam
PART A (CLOSED BOOK)
BITS C342 Object Oriented Programming
Date : 11-12-2007 Max.Duration : one hour Max.Marks : 25
Instructions:
(a) Please mention the details regarding your name, Id no, and the part correctly.
(b) Overwriting is allowed but no recheck for such ques. shall be entertained.
(c) Answers marked with pencils will not be corrected.
(d) Assume that all the needed packages are imported in the code.
(e) Ignore errors such as uppercase lowercase errors, semicolon missing if any.
(f) Only 1 accurate ans for Mulitple option ques..
(g) There is no negative marking.
I. Multiple option [0.5*20 = 10M]
1. Which of the subsequent keywords shows a thread is releasing its Object lock?
A) release B) wait C) continue D) notifyAll

2. Which best defines the synchronized keyword?
A) Allows more than 1 Thread to access a method simultaneously
B) Allows more than 1 Thread to find the Object lock on a reference
C) provide the notify/notifyAll keywords exclusive access to the monitor
D) Means only 1 thread at a time can access a method or block of code
3. What will happen when you attempt to compile and run the subsequent code?
public class WaNot{
int i=0;
public static void main(String argv[]){
WaNot w = new WaNot();
w.amethod();
}
public void amethod(){
while(true){
try{
wait();
}catch (InterruptedException e) {}
i++;
}//End of while

}//End of amethod
}//End of class
A)Compile time error, no matching notify within the method
B)Compile and run but an infinite looping of the while method
C)Compilation and run
D)Runtime Exception "IllegalMonitorStateException"
4. How can you specify which thread is notified with the wait/notify protocol?
A) Pass the object reference as a parameter to the notify method
B) Pass the method name as a parameter to the notify method
C) Use the notifyAll method and pass the object reference as a parameter
D) none of the above
5. The statement super( ); does which of the following?
A) calls the method super as described in the current class
B) calls the method super as described in the current class’s parent class
C) calls the method super as described in java.lang
D) calls the constructor as described in the current class
E) calls the constructor as described in the current class’s parent class
6. Aside from permitting inheritance, the visibility modifier protected is also used to
A) permit access to the protected item by any class described in the identical package
B) permit access to the protected item by any static class
C) permit access to the protected item by any parent class
D) ensure that the class can not throw a NullPointerException
E) define abstract elements of an interface
7. All classes in Java are directly or indirectly subclasses of the _______ class.
A) Wrapper
B) String
C) Reference
D) this
E) Object
8. The relationship ranging from a child (sub) class and a parent (super) class is referred to as a(n) ___________ relationship.
A) has-a
B) is-a
C) was-a
D) instance-of
9. What does the subsequent code do? presume list is an initialized array of int values, temp is a few previously initialized int value, and c is an int initialized to 0.
for(int j=0;j if(list[j] < temp)
c++;
A) It obtains the smallest value and stores it in temp
B) It obtains the largest value and stores it in temp
C) It counts the number of elements equal to the smallest value in list
D) It counts the number of elements in list that are less than temp
E) It sorts the values in list to be in ascending order
10. Consider the array declaration and instantiation: int[ ] arr = new int[5]; Which of the subsequent is actual about arr?
A) It stores five elements with legal indices ranging from one and 5
B) It stores five elements with legal indices ranging from 0 and 4
C) It stores four elements with legal indices ranging from one and 4
D) It stores six elements with legal indices ranging from 0 and 5
E) It stores five elements with legal indices ranging from 0 and 5
11. According to Sun's Java two SDK, how many public classes can be declared in a source file?
A) 1
B) 0
C) as many as desired
D) no more than one public class and one public interface
12. When declaring a field, which of the subsequent access-level specifier keywords would you use so that only classes in the identical package as the class that declares the field can access that field?
A) public
B) private
C) protected
D) none of the above

For ques. 13 – 15, use the subsequent partial class definitions:
public class A1
{
public int x;
private int y;
protected int z;

}
public class A2 extends A1
{
protected int a;
private int b;

}
public class A3 extends A2
{
private int q;

}
13. Which of the subsequent lists of instance data are accessible in class A2?
A) x, y, z, a, b
B) x, y, z, a
C) x, z, a, b
D) z, a, b
E) a, b
14. Which of the subsequent lists of instance data are accessible in A3?
A) x, y, z, a, b, q
B) a, b, q
C) a, q
D) x, z, a, q
E) x, a, q
15. Which of the subsequent is actual regarding the use of instance data y of class A1?
F) it is accessible in A1, A2 and A3
A) it is accessible in A1 and A2
B) it is accessible only in A1
C) it is accessible only in A3
D) it is not accessible to any of the 3 classes

For ques. 16 – 17, consider the subsequent class definition:

public class Test
{ private int x;
public Test(int newValue)
{
x = newValue;
}
}
16. Which of the subsequent is actual about the class Test?
a) it has no parent class
b) it’s parent class is Object
c) it’s parent class is Java
d) it can not be extended
e) it has a default child called Object
17. If q1 and q2 are objects of Test class, then q1.equals(q2)
a) is a syntax fault since equals is not described in the test class
b) is actual if q1 and q2 both store the identical value of x
c) is actual if q1 and q2 reference the identical test object
d) is never actual
e) throws a NullPointerException

Use the code beneath to ans ques. 18 – 20. Note that the catch statements in the code are not implemented, but you will not need those details. presume filename is a String, x is an int, a is a double array and I is an int. Use the comments I1, I2, I3, e1, e2, e3, e4, e5 to ans the ques. (I for instruction, e for exception handler).

try{
BufferedReader infile = new BufferedReader(new FileReader(filename)); //i1
int x = Integer.parseInt(infile.readLine( )); //i2
a[++i] = (double) (1 / x); //i3
} catch (FileNotFoundException ex) {…} // e1
catch (NumberFormatException ex) {…} // e2
catch (ArithmeticException ex) {…} // e3
catch (ArrayIndexOutOfBounds ex) {…} // e4
catch (IOException ex) {…} // e5

18. An exception raised by the instruction in i1 would be caught by the catch statement tagged
A) e1
B) e2
C) e5
D) either e1 or e5
E) either e1, e4 or e5

19. An exception raised by the instruction in i2 would be caught by the catch statement tagged
A) e1
B) e2
C) e3
D) e5
E) either e2 or e5
20. An exception raised by the instruction in i3 would be caught by the catch statement tagged
A) e2
B) e3
C) e4
D) either e3 or e4
E) either e2, e3 or e4


II. True/False [0.5*10 = 5M]
1. A static method can refer to any instance variable of the class.
2. When an instance of a class, or object, is specified as a parameter to a method, a reference to the stated object is passed to the method.
3. All interface methods must be declared as public when implemented in a class.
4. Methods can be overloaded with a difference only in the kind of the return variable.
5. A panel can be placed inside a panel.
6. A method in a class declared as static may be invoked simply by using the name of the method alone.
7. every method in a class must have a unique name.
8. A source object and a listener object can be the identical.
9. The Thread class implements Runnable.
10. You cannot place a method call in a try-catch block unless the method claims an exception.


III. Differentiate ranging from the subsequent in short. [1*5 = 5M]
1. Interface Invariants and Implementation Invariants
2. Shallow Copy and Deep Copy.
3. Constructor and Factory Method.
4. Frame and Window
5. Implicit Parameter and Explicit Parameter


IV. Short Answers [1*5 = 5M]
1. provide 2 examples of tagging interfaces.
2. State 2 instances where we need to use private constructors.
3. What if the main method is declared as private? – Compile Time OR Runtime fault and Why?
4. What provide java it’s “write once and run anywhere” nature?
5. Why static method can't be overridden in Java?

*****************************ALL THE BEST*************************


BIRLA INSTITUTE OF TECHNOLOGY AND SCIENCE, PILANI

FIRST SEMESTER, 2007-2008

COMPREHENSIVE EXAMINATION

PART A (CLOSED BOOK)

BITS C342 Object Oriented Programming

Date : 11-12-2007 Max.Duration : 1 hour Max.Marks : 25

Instructions:

(a)     Please mention the details regarding your name, Id no, and the section correctly.

(b)     Overwriting is allowed but no recheck for such questions shall be entertained.

(c)     Answers marked with pencils will not be corrected.

(d)     Assume that all the required packages are imported in the code.

(e)     Ignore errors such as uppercase lowercase errors, semicolon missing if any.

(f)      Only One correct Answer for Mulitple Choice questions.

(g)     There is no negative marking.

I. Multiple Choice [0.5*20 = 10M]

1. Which of the following keywords indicates a thread is releasing its Object lock?
A) release B) wait C) continue D) notifyAll

 

2. Which best describes the synchronized keyword?

A) Allows more than one Thread to access a method simultaneously
B) Allows more than one Thread to obtain the Object lock on a reference
C) Gives the notify/notifyAll keywords exclusive access to the monitor
D) Means only one thread at a time can access a method or block of code

3. What will happen when you attempt to compile and run the following code?

public class WaNot{
int i=0;
public static void main(String argv[]){
 WaNot w = new WaNot();
 w.amethod();
 }
 public void amethod(){
  while(true){
 try{ 
 wait();
  }catch (InterruptedException e) {}
 i++;
  }//End of while
 
 }//End of amethod
}//End of class
A)Compile time error, no matching notify within the method
B)Compile and run but an infinite looping of the while method
C)Compilation and run
D)Runtime Exception "IllegalMonitorStateException"

4. How can you specify which thread is notified with the wait/notify protocol?

A) Pass the object reference as a parameter to the notify method
B) Pass the method name as a parameter to the notify method
C) Use the notifyAll method and pass the object reference as a parameter
D) none of the above

5. The statement super( ); does which of the following?

A)      calls the method super as defined in the current class

B)      calls the method super as defined in the current classs parent class

C)      calls the method super as defined in java.lang

D)      calls the constructor as defined in the current class

E)      calls the constructor as defined in the current classs parent class

6. Aside from permitting inheritance, the visibility modifier protected is also used to

A)      permit access to the protected item by any class defined in the same package

B)      permit access to the protected item by any static class

C)      permit access to the protected item by any parent class

D)      ensure that the class can not throw a NullPointerException

E)      define abstract elements of an interface

7. All classes in Java are directly or indirectly subclasses of the _______ class.

A)      Wrapper

B)      String

C)      Reference

D)      this

E)      Object

8. The relationship between a child (sub) class and a parent (super) class is referred to as a(n) ___________ relationship.

A)      has-a

B)      is-a

C)      was-a

D)      instance-of

9. What does the following code do? Assume list is an initialized array of int values, temp is some previously initialized int value, and c is an int initialized to 0.

for(int j=0;j<list.length; j++)

if(list[j] < temp)

c++;

A)      It finds the smallest value and stores it in temp

B)      It finds the largest value and stores it in temp

C)      It counts the number of elements equal to the smallest value in list

D)      It counts the number of elements in list that are less than temp

E)      It sorts the values in list to be in ascending order

10. Consider the array declaration and instantiation: int[ ] arr = new int[5]; Which of the following is true about arr?

A)      It stores 5 elements with legal indices between 1 and 5

B)      It stores 5 elements with legal indices between 0 and 4

C)      It stores 4 elements with legal indices between 1 and 4

D)      It stores 6 elements with legal indices between 0 and 5

E)      It stores 5 elements with legal indices between 0 and 5

11. According to Sun's Java 2 SDK, how many public classes can be declared in a source file?

A) 1
B) 0
C) as many as desired
D) no more than 1 public class and 1 public interface

12. When declaring a field, which of the following access-level specifier keywords would you use so that only classes in the same package as the class that declares the field can access that field?

A) public
B) private
C) protected
D) none of the above

 

For questions 13 15, use the following partial class definitions:

public class A1

{

public int x;

private int y;

protected int z;

}

public class A2 extends A1

{

protected int a;

private int b;

}

public class A3 extends A2

{

private int q;

}

13. Which of the following lists of instance data are accessible in class A2?

A)      x, y, z, a, b

B)      x, y, z, a

C)      x, z, a, b

D)      z, a, b

E)      a, b

14. Which of the following lists of instance data are accessible in A3?

A)      x, y, z, a, b, q

B)      a, b, q

C)      a, q

D)      x, z, a, q

E)      x, a, q

15. Which of the following is true regarding the use of instance data y of class A1?

F)       it is accessible in A1, A2 and A3

A)      it is accessible in A1 and A2

B)      it is accessible only in A1

C)      it is accessible only in A3

D)      it is not accessible to any of the three classes

 

For questions 16 17, consider the following class definition:

 

public class Test

{ private int x;

public Test(int newValue)

{

x = newValue;

}

}

16. Which of the following is true about the class Test?

a)       it has no parent class

b)       its parent class is Object

c)       its parent class is Java

d)       it can not be extended

e)       it has a default child called Object

17. If q1 and q2 are objects of Test class, then q1.equals(q2)

a)       is a syntax error since equals is not defined in the test class

b)       is true if q1 and q2 both store the same value of x

c)       is true if q1 and q2 reference the same test object

d)       is never true

e)       throws a NullPointerException

 

Use the code below to answer questions 18 20. Note that the catch statements in the code are not implemented, but you will not need those details. Assume filename is a String, x is an int, a is a double array and I is an int. Use the comments I1, I2, I3, e1, e2, e3, e4, e5 to answer the questions (I for instruction, e for exception handler).

 

try{

BufferedReader infile = new BufferedReader(new FileReader(filename)); //i1

int x = Integer.parseInt(infile.readLine( )); //i2

a[++i] = (double) (1 / x); //i3

} catch (FileNotFoundException ex) {} // e1

catch (NumberFormatException ex) {} // e2

catch (ArithmeticException ex) {} // e3

catch (ArrayIndexOutOfBounds ex) {} // e4

catch (IOException ex) {} // e5

 

18. An exception raised by the instruction in i1 would be caught by the catch statement labeled

A) e1

B) e2

C) e5

D) either e1 or e5

E) either e1, e4 or e5

 

19. An exception raised by the instruction in i2 would be caught by the catch statement labeled

A)      e1

B)      e2

C)      e3

D)      e5

E)      either e2 or e5

20. An exception raised by the instruction in i3 would be caught by the catch statement labeled

A)      e2

B)      e3

C)      e4

D)      either e3 or e4

E)      either e2, e3 or e4

 

 

II. True/False [0.5*10 = 5M]

1. A static method can refer to any instance variable of the class.

2. When an instance of a class, or object, is specified as a parameter to a method, a reference to the said object is passed to the method.

3. All interface methods must be declared as public when implemented in a class.

4. Methods can be overloaded with a difference only in the type of the return variable.

5. A panel can be placed inside a panel.

6. A method in a class declared as static may be invoked simply by using the name of the method alone.

7. Each method in a class must have a unique name.

8. A source object and a listener object can be the same.

9. The Thread class implements Runnable.

10. You cannot place a method call in a try-catch block unless the method claims an exception.

 

 

III. Differentiate between the following in short. [1*5 = 5M]

1.      Interface Invariants and Implementation Invariants

2.      Shallow Copy and Deep Copy.

3.      Constructor and Factory Method.

4.      Frame and Window

5.      Implicit Parameter and Explicit Parameter

 

 

IV. Short Answers [1*5 = 5M]

1. Give two examples of tagging interfaces.

2. State two instances where we need to use private constructors.

3. What if the main method is declared as private? Compile Time OR Runtime Error and Why?

4. What gives java its write once and run anywhere nature?

5. Why static method can't be overridden in Java?


*****************************ALL THE BEST******************************


( 0 Votes )

Add comment


Security code
Refresh

Earning:   Approval pending.
You are here: PAPER Birla Institute of Technology (BIT Mesra) 2007 B.E OBJECT ORIENTED PROGRAMMING - Question Paper