• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error!!!

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
FRIENDS, I AM HAVING THE DOUBTS AT THESE QUESTINS , PLZ CLEARED ME...THANX
A)
consider the following
1.public Object methoda()
{
2.Object o=new Object();
3.Object o1[]=new Object[1];
4.o1[0]=o;
5.o=null;
6.o=new Object();
7.o1[0]=null;
8.return o1[0];
}
when will the object o referenced earlier was
available for garbage collector.
a) just after line 4
b) just after line 5
c) just after line 6
d) just after line 7
e) never in this method

B)
Which layout has to be used in the Panel if the
Panel has textArea
Label, button vertically in a window and You want to
Increase the
Height of textArea vertically?
Ans: gridbagLayout

C)
see code which of the following is true?
import java.awt.*;
public class Demo extends Frame
{
public Demo()
{
setLayout(new BorderLayout(2,2));
setSize(300,300);
setVisible(true);
Panel p1=new Panel();
p1.add(new Button("One"));
add(p1);
Panel p2=new Panel();
p2.add(new Button("Two"));
add(p2);
add(new Button("Three"));
add(new Button("Four"));
a) Button "One" will not resize if the frame is
resized
b) Button "Three" will not resize if the frame is
resized
c) Button "One" will be resized if the frame is
resized
d) Button "Three" will be resized if the frame is
resized
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As for u r first question goes when u set to null it is garbage
collected.
so i think option 5 is right

have a nice time
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
Answer to A:
d) just after line 7
this is because even though the reference o has been set to null at line 5 ... there still exsits a reference to it from the array element o1[0] ... hence the Object does not become eligible for garbage collection after this line .... but at line 7 this reference too is set to null and hence the object is free os all references to it and hence after line this Object becomes eligible for garbage collection
\```/
(o o) harder u try luckier u get
-------oOO--(_)--OOo----------------------------
Samith.P.Nambiar
 
Samith Nambiar
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
Answer to C:
a) Button "One" will not resize if the frame is
resized
b) Button "Three" will not resize if the frame is
resized
this is because even though u have set a borderlayout for the frame you do not specify any constants like NORTH,WEST,SOUTH,EAST or CENTER ... hence the line from your code
add(p1); defaults to add(p1,BoerderLayout.CENTER);
due to this all u see is Button four ... because it gets placed one over the other .... but while resizing all get resized
<pre>
\```/
(o o) harder u try luckier u get
-------oOO--(_)--OOo----------------------------
Samth.P.Nambiar
</pre>
 
Ranch Hand
Posts: 1874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Geetha S & Deepak C , Welcome to javaranch.
PRPOER NAMES ARE NOW REQUIRED

Please refer to official javaranch naming policy & reregister yourself with proper first & last name. Please do the needful & help maintain the decorum of he forum.
Waiting for the posts from both of you with proper first & last name. When you reregister with proper names , please let us know , so that your previous accounts will be disabled. That will be done even if you do not copmly with javaranch naming policy.
I think I am quite clear.

Your Friednly Bartender
Shailesh.
[This message has been edited by shailesh sonavadekar (edited May 26, 2001).]
reply
    Bookmark Topic Watch Topic
  • New Topic