• 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

Buttons

 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the following applet, how many Buttons will be displayed?

1: import java.applet.*;
2: import java.awt.*;
3:
4: public class Q16 extends Applet
5: {
6: Button okButton = new Button("Ok");
7:
8: public void init()
9: {
10: add(okButton);
11: add(okButton);
12: add(okButton);
13: add(okButton);
14:
15: add(new Button("Cancel"));
16: add(new Button("Cancel"));
17: add(new Button("Cancel"));
18: add(new Button("Cancel"));
19:
20: setSize(300,300);
21: }
22: }
A) 1 Button with label "Ok" and 1 Button with label "Cancel" .
B) 1 Button with label "Ok" and 4 Buttons with label "Cancel" .
C) 4 Buttons with label "Ok" and 1 Button with label "Cancel" .
D) 4 Buttons with label "Ok" and 4 Buttons with label "Cancel" .

The answer given is A. How ??
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, in this code, first you add the same instance of Button, okButton, over and over again - so there's only one "OK" button, even though you've added it several times. Then you create four different new buttons with new Button(), each with the label "Cancel", and add them to the applet - so there are four "Cancel" buttons.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the answer is b)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic