Could anyone explain the two questions below?? Q1) import java.awt.*; import java.awt.event.*;
public class Test { public static void main( String args[] ) { String s = "Happy"; Frame f = new Frame(); Button btn = new Button(); btn.addActionListener( new ActionListener(){ public void actionPerformed( ActionEvent e ){ System.out.println( "Message is " + s ); } } ); f.add( btn ); f.setVisible( true ); } }
��A. both compile and runtime is successful but nothing is displayed ��B. both compile and runtime is successful and if you click button display "Message is Happy ��C. compile is successful but runtime is fail ��D. compile is failed because String s cannot be used ......... ��E. compile is failed because class Test ......... not implements ActionListener
ans) D why??
Q2 48. Which statement is true about GridBagLayout ?
��A. Values of weightx and weighty must be in the range 0.0 to 1.0 ��B. The fill value for a component is irrelavant if the anchar value is CENTER ��C. The last component in a row must be flagged using the REMAINDER value ��D. The anchor value for a component is irrelavant if the fill value for the component is BOTH ��E. At most one row can change height and at most one column may change width when the container is resized
ans ?? thank you so much!
V Srinivasan
Ranch Hand
Joined: Aug 16, 2000
Posts: 99
posted
0
Hi, Anonymous Inner Class can access only the final variables of enclosing Class. If you say final string s = "Happy" it will work. Thanks & regards, V.Srinivasan
Daniel Wu
Ranch Hand
Joined: Jun 13, 2001
Posts: 58
posted
0
Originally posted by kevin goon: 48. Which statement is true about GridBagLayout ?
��A. Values of weightx and weighty must be in the range 0.0 to 1.0 ��B. The fill value for a component is irrelavant if the anchar value is CENTER ��C. The last component in a row must be flagged using the REMAINDER value ��D. The anchor value for a component is irrelavant if the fill value for the component is BOTH ��E. At most one row can change height and at most one column may change width when the container is resized
ans ?? thank you so much!
I think the answer is D.
Jyotsna Umesh
Ranch Hand
Joined: May 09, 2001
Posts: 94
posted
0
For Question 1 D option is right but i think E should also be right as the class needs to implement ActionListener, isn't it? For ques. 2 I think ans. is D Jyotsna
Scott Appleton
Ranch Hand
Joined: May 07, 2001
Posts: 195
posted
0
Jyotsna, for Q1 answer E is incorrect because class Test does not have to implement the ActionListener interface. Test is not acting as an ActionListener -- the button btn is acting as its own ActionListener by creating an anonymous implementation of an ActionListener and adding that implementation as an ActionListener in the same statement.
Jyotsna Umesh
Ranch Hand
Joined: May 09, 2001
Posts: 94
posted
0
Thanks Scott, I missed the point. Jyotsna
kevin goon
Ranch Hand
Joined: Jun 12, 2001
Posts: 62
posted
0
int m = 0; while (m++ < 2) System.out.println(m);
prints 1,2 why?
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.