Originally posted by ratul banji:
q1.In the following code, which is the earliest statement, where the object originally held in e, may be garbage collected:
1.public class Test {
2.public static void main (String args []) {
3.Employee e = new Employee("Bob", 48);
4.e.calculatePay();
5.System.out.println(e.printDetails());
6.e = null;
7.e = new Employee("Denise", 36);
8.e.calculatePay();
9.System.out.println(e.printDetails());
10.}
11.}
a.Line 10
b.Line 11
c.Line 7
d.Line 8
e.Never
Select the most appropriate ans.
whenever we have an object with no reference left it is elgible to be garbage collected.Here at line six new Employee("bob",48) has no reference variable pointing to it.so after the 6th line object can be garbage collected.
The answer is given c , but I think it should be b.
correct me if I am wrong.
q2.What is the effect of adding the sixth element to a vector created in the following manner:
new Vector(5, 10);
a.An IndexOutOfBounds exception is raised.
b.The vector grows in size to a capacity of 10 elements
c.The vector grows in size to a capacity of 15 elements
d.Nothing, the vector will have grown when the fifth element was added
vector is nothing but a dynamical array whose size automatically increases with the programmers needs.But to do that there are two ways either to increase the size while u add the element or to increase reallocate space for a no of elements together.Reallocation is infact a costly phenoemena so the collections handle it by providing space for more than what is needed.Now when u add the sixth element u increase the initial size 5 ,10 more spaces for objects are added.Hence the size 15.
Select the most appropriate answer.
The answer is given c..may be right..but how can it be !
Vector (5,10) means initial capacity 5, additional allocation (capacity increment) by 10,right.Then....
q3. Examine the following code which includes an inner class:
public final class Test4 implements A {
class Inner {
void test() {
if (Test4.this.flag); {
sample();
}
}
}
private boolean flag = false;
public void sample() {
System.out.println("Sample");
}
public Test4() {
(new Inner()).test();
}
public static void main(String args []) {
new Test4();
}
}
What is the result:
A. Prints out "Sample"
B. Program produces no output but terminates correctly.
C. Program does not terminate.
D. The program will not compile
Select the most appropriate answer.
In inner classes too this refers to the object of present class
So inside Inner class this.someVariable refers to the inner class member and outerclassname.this.somevariable and super.this,somevariable refer to the outer class and Super class member respectively.I hope now u get why the answer is A
Answer is given A i.e. prints 'sample'
q4.What class must an inner class extend:
a.The top level class
b.The Object class
c.Any class or interface
d.It must extend an interface
e.Select the most appropriate
Select the most appropriate answer.
I have already answered this question somewhere.
The question in my opinion should be
What class can an inner class extend??? and not must!!!
An inner class can extend any class or interface.So C is the right answer.
Answer is given C
But the q. states that it is MUST...is it must for inner class to extend any class or object .I don't think so. I think the answer should be B . B'cause by default every class extends object class.
THANKS IN ADVANCE.
<marquee>[b] Ratul Banerjee </marqyee>
[/B]
vkswami
vkswami
please buy my thing and then I'll have more money:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|