• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

HUNT's mock exam...pls..help

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

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

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.

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.
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> Ratul Banerjee </marqyee>

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ratul,
q1.I think the correct answer is c as the object originally held by e i.e ("Bob", 48) is no longer accessible from line 7 onwards as it points towards a new Employee object ("Denise", 36).
As for the second question, check out the constructors for Vector.The vector has a capacity increment of 10, so when it reaches 5 elements, it's capacity increases to 5+10=15
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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]


 
ratul banji
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nandini , Sandeep,
Thanks to both of u.
But, I have some doubt abt. the last one.
The q. states that "MUST" ..then wht. should be the answer.
and why not the B(object class) as we all know class by default extend Object class.
Thanks.
Ratul Banerjee.
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q3.
Since the value of flag is set to false, the sample() method should not execute. Is this not true?
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Parimala
didn't U see the ' ; ' after if condition.This makes the sample running.careful reading.
with regards
vkswami
 
vkswamy venkatachalam
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Parimala
Q3.Didn't U see the ' ; ' after if condition.This makes the sample running.careful reading.
with regards
vkswami
 
Then YOU must do the pig's work! Read this tiny ad. READ IT!
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic